Logo 
Search:

C++ Programming FAQ

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

Write an algorithm for Pushing a Node above the top of stack using Singly Linked List in dfs

  Shared By: Sarah Hughes    Date: May 25    Category: C++ Programming    Views: 3082

Answer:

PROCEDURE PUSH_STACK(TOP)
[Where top of the stack has been caught in pointer ‘TOP’]

1. [Allocating the memory for new node & pushing it into stack]

Call GETNODE (I)
DATA (P) <-- ‘xyz’
LINK (P) <-- TOP
TOP <-- P
return (TOP).

2. [FINISH]
return.

Share: 
 


Related Topics:

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


Tagged: