Logo 
Search:

C++ Programming FAQ

Submit Interview FAQ
Home » Interview FAQ » C++ ProgrammingRSS Feeds

Write an algorithm for Creating Stack (lifo) using Singly Linked List in dfs.

  Shared By: Morgan Brown    Date: Apr 03    Category: C++ Programming    Views: 5221

Answer:

PROCEDURE CREATE_STACK(TOP)
[Where ‘head’ pointer has been caught in pointer ‘TOP’ and link of head has done NULL]

1. [Allocating memory for new node & having the value from user]

Call GETNODE (TOP)
DATA (TOP) <-- ‘xyz’
LINK (TOP) <-- S.
S <-- TOP.

2. [Checking the value & calling the function recursiverly]

if(DATA (TOP) <= 0)
return (LINK(TOP))
else
Call CREATE_STACK (TOP)

3. [FINISH]
return.

Share: 
 


Related Topics:

Your Comment
  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].


Tagged: