//following line calls the function linear with
the parameters array of keys (a), total //keys (n) in the array, and the key (key) to be searched. The result
returned by the //function stored in variable ‘found_at’.

found_at =
linear(a, n, key);

if(found_at!=-1)

printf("\nData is present at position %d", found_at);

else

printf("\nData not present");

getch();

}

int linear(int a[], int tot_keys, int k)

{

int i, position =
-1;

for(i=0; i < tot_keys;
i++) //this loop executes the number of keys time

if(a[i]==k) //checks if the key at position i is equal to key to be
searched

Wednesday, 24 January 2018

C
program for implementing balanced parentheses using Stack ADT using array explained,
How to implement stack ADT using array for balanced parentheses? How to implement
stack data structure using linear array in C?

Implementation
of balanced parentheses using stack with array

/* This program
implements balanced parentheses using stack with array. It handles [], (), and {}
brackets. In the input string, if the brackets are not balanced, then the
program shows “Unbalanced” otherwise shows “Balanced” as result.

Working

The program scans the
input string from left to right character by character. If the scanned
character is opening bracket, then inserts the character on to the stack. If the
scanned character is closing symbol ( ‘)’, ‘]’, ‘}’ ), then the program pops
the top element. */