C# example- sequential search algorithm

Sequential search algorithm



This is C# example code for a sequential search algorithm. If you are not sure about the sequential search process you can visit this page:

Algorithm and Data Structure tutorial  

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
class Program
{

static void Main(string[] args)
{
   int[] arr= new int[5]{23,2,3,34,6}; //unsorted data set
   int pos;
   pos=seqsearch(arr,2,5);
   if(pos!=-1)
     Console.WriteLine("The target item was found at location:{0}",pos);
   else
   Console.WriteLine("The target item was not found in the list.\n");
   Console.ReadLine();

}
///sequential search
static int seqsearch(int[] dataset,int target,int n){
  int found=0;
  int i;
  int pos=-1;
  for(i=0;i<n && found!=1;i++)
    if(target==dataset[i]){pos=i;found=1;}

  return pos;
    
}
  
}
}





Comments

Name:
Comment:
Enter the text:
CAPTCHA image

....................................................................................................................Home | Forum | About | Contact
This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.
Copyright @ 2011-2013 worldbestlearningcenter. All Rights Reserved.
Home Programming Web DB & App Questions Exercises Tips Programs FAQs Download About
Computer-Wbest
Popular Pages
You might like