Program for linear search, Data Structure & Algorithms

Assignment Help:

Program for Linear Search.

Program: Linear Search

/*Program for Linear Search*/

/*Header Files*/

#include

#include

/*Global Variables*/

int search;

int flag;

/*Function Declarations*/

int input (int *, int, int);

void linear_search (int *, int, int);

void display (int *, int);

/*Functions */

void linear_search(int m[ ], int n, int el)

{

int k;

flag = 1;

for(k=0; k

{

if(m[k]==el

{

printf("\n Searching is Success\n");

printf("\n Element : %i Found at location : %i", element, k+1);

flag = 0;

}

}

if(flag==1)

printf("\n Searching is unsuccessful");

}

void display(int m[ ], int n)

{

int i;

for(i=0; i< 20; i++)

{

printf("%d", m[i];

}

}

int input(int m[ ], int n, int el)

{

int i;

n = 20;

el = 30;

printf("Number of elements in the list : %d", n);

for(i=0;i<20;i++)

{

m[i]=rand( )%100;

}

printf("\n Element to be searched :%d", el);

search = el;

return n;

}

/* Main Function*/

void main( )

{

int n, el, m[200];

number = input(m, n,el);

el = search;

printf("\n Entered list: \n");

display(m, n);

linear_search(m, n, el);

printf("\n In the following list\n");

display(m, n);

}

Program 1 examines each key value in the array 'm', one by one and stops while a match occurs or the entire array is searched.


Related Discussions:- Program for linear search

Program for all pairs shortest paths algorithm, Program segment for All pai...

Program segment for All pairs shortest paths algorithm AllPairsShortestPaths(int N, Matrix C, Matrix P, Matrix D) { int i, j, k if i = j then C[i][j] = 0  for ( i =

Pseudo code, since the gregorian calendar was introduced in 1752,a leap yea...

since the gregorian calendar was introduced in 1752,a leap year occurs every 4 years.you are to write a pseudo code to find out whether a year is a leap year.your progrm should dis

Compound interest, Write the algorithm for compound interest

Write the algorithm for compound interest

Abstract data type-tree, Definition: A set of data values & related operati...

Definition: A set of data values & related operations that are accurately specified independent of any particular implementation. As the data values and operations are described

Elaborate the symbols of abstract data type, Elaborate the symbols of abstr...

Elaborate the symbols of abstract data type length(a)-returns the number of characters in symbol a. capitalize(a)-returns the symbol generated from a by making its first cha

Explain in detail about the ruby arrays, Explain in detail about the Ruby a...

Explain in detail about the Ruby arrays Ruby arrays have many interesting and powerful methods. Besides indexing operations which go well beyond those discussed above, arrays h

Explain b- tree, B- Tree  A B-tree of order m is an m-way true in which...

B- Tree  A B-tree of order m is an m-way true in which  1)  All leaves are on the similar level 2)  All internal nodes except the root have at most m-1(non-empty) childre

Selection sort, how to reduce the number of passes in selection sort

how to reduce the number of passes in selection sort

B – trees, B-trees are special m-ary balanced trees utilized in databases s...

B-trees are special m-ary balanced trees utilized in databases since their structure allows records to be added, deleted & retrieved with guaranteed worst case performance. A B-

Total impedent of the circuit, an electrical student designed a circuit in...

an electrical student designed a circuit in which the impedence in one part of a series circuit is 2+j8 ohms and the impedent is another part of the circuit is 4-j60 ohm mm program

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd