Skip to main content
Commonmark migration
Source Link
added 236 characters in body; edited tags
Source Link
Cliff B
  • 69.3k
  • 4
  • 33
  • 56

#include <cs50.h>

#include "helpers.h"

#include <cs50.h>
#include "helpers.h"

bool search(int value, int values[], int n)
    {
    // is array filled?
    if (n <= 0)
    {
        return false;
    }
    
    int start = 0;
    int end = n - 1;
    int mid = (start + end) / 2;
    
    // iterate through each value within array 
    while (start <= end)
    {
        if (values[mid] == value)
        {
            return true;
        }
                
        if (values[mid] << value)
        {
            start = mid + 1;
            mid = (start + end) / 2;
        }
        
        else if (values[mid] >> value)
        {
            end = mid - 1;
            mid = (start + end) / 2;
        }
    }
    return false;
}




void sort(int values[], int n)
{
    int temp;
    int i, j;
    int swapcount = 0;
    
    for (i = 0; i < n - 1; i++)
    {
        for (j = 0; j < n - 1 - i; j++)
        {
            if (values[j] > values[j+1])
            {
                temp  = values[j];
                values[j] = values[j+1];
                values[j+1] = temp;
                swapcount = swapcount + 1;
            }
        }
    
        if (swapcount == 0)
        {
            break;
        }
    }
}

#include <cs50.h>

#include "helpers.h"

bool search(int value, int values[], int n)
{
// is array filled?
if (n <= 0)
{
    return false;
}

int start = 0;
int end = n - 1;
int mid = (start + end) / 2;

// iterate through each value within array 
while (start <= end)
{
    if (values[mid] == value)
    {
        return true;
    }
            
    if (values[mid] << value)
    {
        start = mid + 1;
        mid = (start + end) / 2;
    }
    
    else if (values[mid] >> value)
    {
        end = mid - 1;
        mid = (start + end) / 2;
    }
}
return false;
}




void sort(int values[], int n)
{
int temp;
int i, j;
int swapcount = 0;

for (i = 0; i < n - 1; i++)
{
    for (j = 0; j < n - 1 - i; j++)
    {
        if (values[j] > values[j+1])
        {
            temp  = values[j];
            values[j] = values[j+1];
            values[j+1] = temp;
            swapcount = swapcount + 1;
        }
    }

    if (swapcount == 0)
    {
        break;
    }
}
}
#include <cs50.h>
#include "helpers.h"

bool search(int value, int values[], int n)
    {
    // is array filled?
    if (n <= 0)
    {
        return false;
    }
    
    int start = 0;
    int end = n - 1;
    int mid = (start + end) / 2;
    
    // iterate through each value within array 
    while (start <= end)
    {
        if (values[mid] == value)
        {
            return true;
        }
                
        if (values[mid] << value)
        {
            start = mid + 1;
            mid = (start + end) / 2;
        }
        
        else if (values[mid] >> value)
        {
            end = mid - 1;
            mid = (start + end) / 2;
        }
    }
    return false;
}




void sort(int values[], int n)
{
    int temp;
    int i, j;
    int swapcount = 0;
    
    for (i = 0; i < n - 1; i++)
    {
        for (j = 0; j < n - 1 - i; j++)
        {
            if (values[j] > values[j+1])
            {
                temp  = values[j];
                values[j] = values[j+1];
                values[j+1] = temp;
                swapcount = swapcount + 1;
            }
        }
    
        if (swapcount == 0)
        {
            break;
        }
    }
}
added helper.c
Source Link

#include <cs50.h>

#include "helpers.h"

bool search(int value, int values[], int n)
{
// is array filled?
if (n <= 0)
{
    return false;
}

int start = 0;
int end = n - 1;
int mid = (start + end) / 2;

// iterate through each value within array 
while (start <= end)
{
    if (values[mid] == value)
    {
        return true;
    }
            
    if (values[mid] << value)
    {
        start = mid + 1;
        mid = (start + end) / 2;
    }
    
    else if (values[mid] >> value)
    {
        end = mid - 1;
        mid = (start + end) / 2;
    }
}
return false;
}




void sort(int values[], int n)
{
int temp;
int i, j;
int swapcount = 0;

for (i = 0; i < n - 1; i++)
{
    for (j = 0; j < n - 1 - i; j++)
    {
        if (values[j] > values[j+1])
        {
            temp  = values[j];
            values[j] = values[j+1];
            values[j+1] = temp;
            swapcount = swapcount + 1;
        }
    }

    if (swapcount == 0)
    {
        break;
    }
}
}

#include <cs50.h>

#include "helpers.h"

bool search(int value, int values[], int n)
{
// is array filled?
if (n <= 0)
{
    return false;
}

int start = 0;
int end = n - 1;
int mid = (start + end) / 2;

// iterate through each value within array 
while (start <= end)
{
    if (values[mid] == value)
    {
        return true;
    }
            
    if (values[mid] << value)
    {
        start = mid + 1;
        mid = (start + end) / 2;
    }
    
    else if (values[mid] >> value)
    {
        end = mid - 1;
        mid = (start + end) / 2;
    }
}
return false;
}




void sort(int values[], int n)
{
int temp;
int i, j;
int swapcount = 0;

for (i = 0; i < n - 1; i++)
{
    for (j = 0; j < n - 1 - i; j++)
    {
        if (values[j] > values[j+1])
        {
            temp  = values[j];
            values[j] = values[j+1];
            values[j+1] = temp;
            swapcount = swapcount + 1;
        }
    }

    if (swapcount == 0)
    {
        break;
    }
}
}
Source Link
Loading