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

Explain about the preconditions assertion, Preconditions assertion A ...

Preconditions assertion A precondition is an assertion which should be true at the initiation of an operation. For instance, a square root operation can't accept a negative a

Functions for inserting and deleting at either of the end, Q. Develop a rep...

Q. Develop a representation for a list where insertions and deletions can be done at either end. Such a structure is known as a Deque (Double ended queue). Write functions for inse

What is ruby, What is Ruby Ruby has numerous simple types, including nu...

What is Ruby Ruby has numerous simple types, including numeric classes such as Integer, Fixnum, Bignum, Float, Big Decimal, Rational, and Complex, textual classes like String,

Binary search tree, write an algorithm to delete an element x from binary...

write an algorithm to delete an element x from binary search with time complex

Determine the term - loops, Loops There are 3 common ways of performin...

Loops There are 3 common ways of performing a looping function: for ... to ... next, while ... endwhile and repeat ... until The below example input 100 numbers and find

Conversion of general trees into the binary trees, By taking an appropriate...

By taking an appropriate example explain how a general tree can be represented as a Binary Tree.                                                                    C onversio

Interest, I =PR/12 Numbers of years .Interest rate up to 1yrs ...

I =PR/12 Numbers of years .Interest rate up to 1yrs . 5.50 up to 5yrs . 6.50 More than 5 yrs . 6.75 design an algorithm based on the above information

Algorithm to sort a given list by quick sort method, Q. Write down an algor...

Q. Write down an algorithm to sort a given list by making use of Quick sort method. Describe the behaviour of Quick sort when input given to us is already sorted.

Explain the rgb model, RGB Model The RGB model is based on the assumpti...

RGB Model The RGB model is based on the assumption that any desired shade of colour can be obtained by mixing the correct amounts of red, green, and blue light. The exact hues

Complete trees, This is a k-ary position tree wherein all levels are filled...

This is a k-ary position tree wherein all levels are filled from left to right. There are a number of specialized trees. They are binary trees, AVL-trees, binary search trees, 2

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