sequential search

search algorithm

Page 1 of 1

4 Replies - 4819 Views - Last Post: 19 December 2010 - 03:20 PM Rate Topic: -----

#1 empty_heart  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 19-December 10

sequential search

Posted 19 December 2010 - 02:55 PM

the sequential search algorithm will always find the first occurrence of an item in a data set create a new sequential search method that takes a second integer argument indicating which occurrence of an item you want to search for
static void Main(string[] args)
        {
            Console.WriteLine("enter array size");
            int n=int.Parse(Console.ReadLine());
            Console.WriteLine("enter target");
            int target = int.Parse(Console.ReadLine());
             int x=  search(int arr,int target);
            Console.WriteLine("item="+x);
            Console.ReadLine();

        }
        static int search(int arr,int value)
        {
            Console.WriteLine("enter size");
            int n=int.Parse(Console.ReadLine());
            for (int i = 0; i < n; i++)
            {
                if (arr[i] == value)
                {
                    i++;
                    if ((i + 1) == value)
                    {
                        return arr[i + 1];
                    }
                }
            }
        }


MOD EDIT: When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 19 December 2010 - 02:57 PM


Is This A Good Question/Topic? 0
  • +

Replies To: sequential search

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5951
  • View blog
  • Posts: 23,214
  • Joined: 23-August 08

Re: sequential search

Posted 19 December 2010 - 02:59 PM

Copy and paste the errors exactly as they appear.
Was This Post Helpful? 0
  • +
  • -

#3 empty_heart  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 19-December 10

Re: sequential search

Posted 19 December 2010 - 03:02 PM

[code]Error 1 Cannot apply indexing with [] to an expression of type 'int' C:\Documents and Settings\Administrator\Local Settings\Application Data\Temporary Projects\ConsoleApplication1\Program.cs 27 21 ConsoleApplication1
Error 2 The name 'target' does not exist in the current context C:\Documents and Settings\Administrator\Local Settings\Application Data\Temporary Projects\ConsoleApplication1\Program.cs 27 31 ConsoleApplication1
Error 3 Cannot apply indexing with [] to an expression of type 'int' C:\Documents and Settings\Administrator\Local Settings\Application Data\Temporary Projects\ConsoleApplication1\Program.cs 32 32 ConsoleApplication1
Error 4 Invalid expression term 'int' C:\Documents and Settings\Administrator\Local Settings\Application Data\Temporary Projects\ConsoleApplication1\Program.cs 16 33 ConsoleApplication1
Error 5 ; expected C:\Documents and Settings\Administrator\Local Settings\Application Data\Temporary Projects\ConsoleApplication1\Program.cs 16 36 ConsoleApplication1
Error 6 Invalid expression term ',' C:\Documents and Settings\Administrator\Local Settings\Application Data\Temporary Projects\ConsoleApplication1\Program.cs 16 36 ConsoleApplication1
Error 7 ; expected C:\Documents and Settings\Administrator\Local Settings\Application Data\Temporary Projects\ConsoleApplication1\Program.cs 16 37 ConsoleApplication1
Error 8 ; expected C:\Documents and Settings\Administrator\Local Settings\Application Data\Temporary Projects\ConsoleApplication1\Program.cs 16 47 ConsoleApplication1
Error 9 Invalid expression term ')' C:\Documents and Settings\Administrator\Local Settings\Application Data\Temporary Projects\ConsoleApplication1\Program.cs 16 47 ConsoleApplication1
Was This Post Helpful? 0
  • +
  • -

#4 CodingSup3rnatur@l-360  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 982
  • View blog
  • Posts: 969
  • Joined: 30-September 10

Re: sequential search

Posted 19 December 2010 - 03:14 PM

Hello there,

The parameter 'arr' is of type int, and you therefore cannot use index notation on it. Index notation (arr[i]) can only be applied to collections and arrays, or, more specifically, types that implement the IList (or IList<T>) interface. It looks like you need to change the parameter type to an array (or list) of integers and actually pass in an array of integers to search.

This post has been edited by CodingSup3rnatur@l-360: 19 December 2010 - 03:15 PM

Was This Post Helpful? 0
  • +
  • -

#5 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5316
  • View blog
  • Posts: 11,355
  • Joined: 02-June 10

Re: sequential search

Posted 19 December 2010 - 03:20 PM

Is there a reason you have posted this question 3 times under different names?

Quote

Guest has just posted a new topic entitled "problem with sequential search" in forum "C#".

----------------------------------------------------------------------
the sequential search algorithm will always find the first occurrence of an item in a data set. Create a new sequential search method that takes a second integer argument indicating which occurrence of an item you want to search for.with c#
----------------------------------------------------------------------

The topic can be found here:
http://www.dreaminco...howtopic=206032


Quote

cis flower has just posted a new topic entitled "problem with sequential search" in forum "C#".

----------------------------------------------------------------------
the sequential search algorithm will always find the first occurrence of an item in a data set. Create a new sequential search method that takes a second integer argument indicating which occurrence of an item you want to search for.with c#
----------------------------------------------------------------------

The topic can be found here:
http://www.dreaminco...howtopic=206033


Quote

empty_heart has just posted a new topic entitled "sequential search" in forum "C#".

----------------------------------------------------------------------
the sequential search algorithm will always find the first occurrence of an item in a data set create a new sequential search method that takes a second integer argument indicating which occurrence of an item you want to search for static void Main(string ;
}
}
}
}
----------------------------------------------------------------------

The topic can be found here:
http://www.dreaminco...howtopic=206138

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1