Stack making use of the linked list, Data Structure & Algorithms

Q. Implement a stack making use of the linked list. Show the PUSH and POP operations both.

Ans.

Stack implemantation using linked list

# include

# include

struct link

{

int info ;

struct link *next;

}   *start;

struct link * push (struct link * rec)

{

struct link *new_rec;

printf ("\n Input the new value for next location of the stack:") ;

new_rec = (struct link *) malloc (size of

(struct link)) ;

scanf ("%d", &new_rec->info) ;

new_rec->next = rec;

rec = new_rec;

return (rec);

}

struct link * pop (struct link * rec)

{

struct link * temp ;

if (rec == NULL)

{

}

else

{

printf ('\n Stack is empty") ;

temp = rec; rec= temp->next;

printf("the popped element %d", temp->.info);

free(temp) ;

return(rec);

}

Posted Date: 7/13/2012 2:43:24 AM | Location : United States







Related Discussions:- Stack making use of the linked list, Assignment Help, Ask Question on Stack making use of the linked list, Get Answer, Expert's Help, Stack making use of the linked list Discussions

Write discussion on Stack making use of the linked list
Your posts are moderated
Related Questions
Polynomials like  5x 4    +  2x 3    +  7x 2     +  10x  -  8  can  be  represented by using arrays. Arithmetic operations such as addition & multiplication of polynomials are com

Write the algorithm for compound interest

We might sometimes seek a tradeoff among space & time complexity. For instance, we may have to select a data structure which requires a lot of storage to reduce the computation tim

How do collisions happen during hashing? Usually the key space is much larger than the address space, thus, many keys are mapped to the same address. Assume that two keys K1 an

We have discussed that the above Dijkstra's single source shortest-path algorithm works for graphs along with non-negative edges (like road networks). Given two scenarios can emerg

Determine about the logic gates Many electronic circuits operate using binary logic gates. Logic gates essentially process signals that represent true or false or equivalent i.

State the example of pre- and post-conditions Suppose that function f(x) should have a non-zero argument and return a positive value. We can document these pre- and post-condit

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

Sorting is significant application activity. Several sorting algorithms are obtainable. But, each is efficient for a specific situation or a specific kind of data. The choice of a

Data array A has data series from 1,000,000 to 1 with step size 1, which is in perfect decreasing order. Data array B has data series from 1 to 1,000,000, which is in random order.