0
/**
 * helpers.c
 *
 * Helper functions for Problem Set 3.
 */

#include <cs50.h>

#include "helpers.h"


#define bound 200
/**
 * Returns true if value is in array of n values, else false.
 */
bool search(int value, int values[], int n)
{
    int start=0;
    int end=n-1;
    while(start<=end)
    {
        int middle=(start+end) /2;

        if(value==values[middle])
        {
            return true;
        }
        else if(value<values[middle])
        {
            end=middle-1;
        }
        else if(value>values[middle])
        {
            start=middle+1;
        }
    }
    return false;
}

/**
 * Sorts array of n values.
 */
void sort(int values[], int n)
{
    int temp[bound+1]={0};
    //for(int i=0;i<bound+1;i++)
      //  temp[i]=0;
    for(int i=0;i<n;i++)
    {
        int value=values[i];
        temp[value]++;
    }
    for(int i=0;i<bound+1;i++)
    {
        int no=temp[i];
        for(int j=0;j<no;j++)
        {
           values[j]=i;
        }
    }
   //return;
}
3
  • What is bound? What are the contents of bound? Please add related code to question. – Cliff B Sep 4 '17 at 0:19
  • i have added he whole code(bound included) – Medhat_Alhaddad Sep 4 '17 at 0:34
  • I see on Facebook that you've found the problem and solved it. Can you please post your solution as an answer and then accept it? That way, this will be removed from the 'open' list. Thanks. – curiouskiwi Sep 4 '17 at 1:17
0

I was over writing on values[m] every time I reset j;so I declared a new independent index int m=0; for(int i=0;i

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .