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

How to construct binary tree, Q. A Binary tree comprises 9 nodes. The preor...

Q. A Binary tree comprises 9 nodes. The preorder and inorder traversals of the tree yield the given sequence of nodes: Inorder :          E     A    C    K    F     H    D

Link list, algorithm for multiplication of two sparse matrices using link l...

algorithm for multiplication of two sparse matrices using link list

Define ordinary variable, Ordinary variable An ordinary variable of a e...

Ordinary variable An ordinary variable of a easy data type can store a one element only

Algorithm for binary search, Q. Write down the algorithm for binary search....

Q. Write down the algorithm for binary search. Which are the conditions under which sequential search of a list is preferred over the binary search?

Multiple stacks, how multiple stacks can be implemented using one dimension...

how multiple stacks can be implemented using one dimensional array

Operations on b-trees, Operations on B-Trees Given are various operatio...

Operations on B-Trees Given are various operations which can be performed on B-Trees: Search Create Insert B-Tree does effort to minimize disk access and t

frequenty count of function, Ask question find frequency count of function...

Ask question find frequency count of function- {for(i=1;i {for(j=1;j {for(k=1;k } } }

Cohen sutherland algorithm, Using the cohen sutherland. Algorithm. Find the...

Using the cohen sutherland. Algorithm. Find the visible portion of the line P(40,80) Q(120,30) inside the window is defined as ABCD A(20,20),B(60,20),C(60,40)and D(20,40)

C++, #What is the pointer

#What is the pointer

Which is the most suitable data type, Problem 1. You are asked to store...

Problem 1. You are asked to store Names of all 100 students of class A in your Learning Centre. Which data type will you use? What is its syntax? Explaining the data typ

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