I am going round and round in circles with this pset, please can someone give me some direction, below is a copy of my code:
/**
* helpers.c
*
* Helper functions for Problem Set 3.
*/
#include <cs50.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "helpers.h"
/**
* Returns true if value is in array of n values, else false.
*/
bool search(int value, int values[], int n)
// TODO: implement a searching algorithm
{
int low = 0;
int high = n-1;
int mid = low + ((high - low) / 2);
// while length of list is greater than two
while (n > 2)
{
// if middle of values is equal to value, return true
if (mid == value)
return true;
// else if middle of values is greater than value, look to the left
if (mid > value)
mid = low + ((mid-1 - low) / 2);
//else if middle of values is less than value, look to the right
if (mid < value)
mid = low + ((high - mid+1) / 2);
}
//else return false
return false;
// Swap function
void swap(int *a, int *b)
{
int temp = *a;
*a = *b;
*b = temp;
}
/**
* Sorts array of n values.
*/
void sort(int values[], int n);
// TODO: implement an O(n^2) sorting algorithm
int current;
int swapd = n-1;
for(int i = 0; i < n-1; i++)
{
current = values[i];
if (current > i+1)
swap (current, i);
else //(swapd == 0);
return false;
}
}
return;