Linear search

This is a discussion on Linear search within the C++ Programming forums, part of the General Programming Boards category; hi guyz, i am working on this c++ assignment: 1. Linear Search I made this function and it goes through ...

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    19

    Linear search

    hi guyz, i am working on this c++ assignment:

    1. Linear Search

    I made this function and it goes through a list of int values but i want to modify it so that it goes through all the names and returns the name found. Plz help me out guyz

    Code:
    int searchList(int list[], int numElems, int value)
    {
       int index = 0;      // Used as a subscript to search array
       int position = -1;  // To record position of search value
       bool found = false; // Flag to indicate if value was found
    
       while (index < numElems && !found)
       {
          if (list[index] == value) // If the value is found 
          { 
             found = true; // Set the flag 
             position = index; // Record the value's subscript
          }
          index++; // Go to the next element
       }
    return position; // Return the position, or -1


    this is wat i have so far!


    i was missing the following info:

    File for names and marks:

    Collins Bill 80
    Smith Bart 75
    Allen Jim 82
    Griffin Jim 55
    Stamey Marty 90
    Rose Geri 78
    Taylor Terri 56
    Johnson Jill 77
    Allison Jeff 45
    Looney Joe 89
    Wolfe Bill 63
    James Jean 72
    Weaver Jim 77
    Pore Bob 91
    Rutherford Greg 42
    Javens Renee 74
    Harrison Rose 58
    Setzer Cathy 93
    Pike Gordon 48
    Holland Beth 79
    Last edited by kingkobra; 12-03-2009 at 02:04 PM. Reason: missing info

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  3. linear search for structure (record) array
    By jereland in forum C Programming
    Replies: 3
    Last Post: 04-21-2004, 07:31 AM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21