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
The number of different directed trees with 3 nodes are ?? The number of disimilar directed trees with three nodes are 3

Explain the halting problem Given a computer program and an input to it, verify whether the program will halt on that input or continue working indefinitely on it.

This notation bounds a function to in constant factors. We say f(n) = Θ(g(n)) if there presents positive constants n 0 , c 1 and c 2 such that to the right of n 0 the value of f

A spanning tree of any graph is only a subgraph that keeps all the vertices and is a tree (having no cycle). A graph might have many spanning trees. Figure: A Graph

Implement multiple stacks in a single dimensional array. Write algorithms for various stack operations for them.

Containers Introduction Simple abstract data types are useful for manipulating simple sets of values, such as integers or real numbers however more complex abstract data t

what do you understand by structured programming?explain with eg. top down and bottem up programming technique

differences between direct and indirect recursion

How can a lock object be called in the transaction? By calling Enqueue and Dequeue in the transaction.

Give the example of bubble sort algorithm For example List: - 7 4 5 3 1. 7 and 4 are compared 2. Since 4 3. The content of 7 is now stored in the variable which was h