Thread: Linear and binary search in c functions

  1. #16
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Do you know how to solve this problem on paper? Why don't you right out the steps for a linear search and list them. The logic above is not what you want.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  2. #17
    Registered User
    Join Date
    Feb 2015
    Posts
    45
    Quote Originally Posted by AndrewHunter View Post
    Do you know how to solve this problem on paper? Why don't you right out the steps for a linear search and list them. The logic above is not what you want.

    my brain is literally stopped
    this is what i came with:
    Code:
    for(i=0;i<10;i++)
       if (list[i]==s)
       {
        printf("%d is found at location %d\n", s,i+1);
        break;
        }
        if (list[i]!=s)
         printf("%d is not found\n",s);
        return -1; 
       } 
    


    it works ! but i don't know if it's logically correct
    what do you think ?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. linear and binary search!!
    By ari01 in forum C++ Programming
    Replies: 1
    Last Post: 02-06-2014, 12:12 AM
  2. Difference Between A Linear Search And Binary Search
    By ImBack92 in forum C Programming
    Replies: 4
    Last Post: 05-12-2011, 08:47 AM
  3. no. of comparisons in linear/binary search
    By alice in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 06-05-2004, 10:55 PM
  4. binary search or linear search
    By vajira in forum C Programming
    Replies: 0
    Last Post: 06-05-2003, 12:42 PM