int arr [100]; /* array to search */
*
Let's write a simple search function:

int *linear _search ( int val) {
int *parr, *parrend = arr + array _length(arr);

for (parr = arr; parr < parrend; parr++) {
      if (* parr == val )
          return parr ;
 }

return NULL;
}

Talking about this problem, parrend is pointing to the end of arr, it is
like arr + 100 same as arr + sizeof(arr)/sizeof(int);
Now loop starts from the array start and then goes till the end and when the
values matches with the val then loop breaks.

Some code in without pointers,

int arr[100];
int *linear _search ( int val) {
int index_start, size;

size = sizeof(arr)/sizeof(int); //100

for (index = 0; index < size; index++) {
      if (parr[index] == val )
          return &parr[index] ;
 }

return NULL;
}

please let me know if you have any comments.

Thanks,
Sathaiah

On Tue, Sep 28, 2010 at 11:34 PM, rahul rai <[email protected]> wrote:

>
> http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-087-practical-programming-in-c-january-iap-2010/lecture-notes/MIT6_087IAP10_lec05.pdf
>
> Thanking In Advance
> --
> Rahul K Rai
> "And The Geek Shall Inherit The Earth"
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<algogeeks%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to