Q: Explain the given code in your own words.
 find(X): traverse the array until X is located.
int find(int X)
{
   int j;
   for(j=1; j < size+1; j++ )
   if( A[j] == X ) break;
   if( j < size+1 ) {  // found X
   current = j;       // current points to where X found
    return 1;  // 1 for true
 }
return 0;Â // 0 (false) indicates not found
find(X): traverse the array until X is located.
// define a function find(x) that takes the an integer x and traverse the array to find the location of x
 int find(int X)
 {
  int j;
  for(j=1; j < size+1; j++ )
  if( A[j] == X ) break;
  if( j < size+1 ) { // X is found
  current = j;    // store the points where x is found in aa variable currentÂ
  return 1; // return 1 if x is found
 }
  return 0; // return 0 if x is found
Comments
Leave a comment