Stacks in C++ (this stack is using linked structure)

Essay by syedraza70 April 2004

download word file, 5 pages 4.3

Downloaded 30 times


* file: stack.cpp *

* desc: C++ assignment *

* Author: Syed R Fayyaz *

* Date: 03-30-2004 *

* *

* Comment: To introduce with the concept of PUSH, pop and display *

*with stacks. Stack is implemented using linked structure*

*which is little difficult from array ADT's but good for *

*polishing programming skills. *


//preprocessor Directives




// global declarations


/* This ADT "stack_node" includes 2 parts one is data and

other one is nodeptr (which sounds like pointer and it

is), so data stores the value and nodeptr records the


struct stack_node // node for item on stack


int data;

struct stack_node *nodeptr;


/*I delared the top ponter as a global one because

I am having problem passing the pointer by reference!

It is always being passed as a paremeter so the changes

are not permanent.


// Start with top of stack set to NULL

// pointer to top of stack

stack_node *top_ptr;


/*Program menu which is always on line 20 can be done easily by using

goto xy function ,which is not considered very good programming in

today's market, To prevent Goto xy in all these functions I am

passing a variable name "Line_break_info" this is the key variable

from which i am keeping track of Line breaks used and then to print

menu always at line 20. Variable is passed by reference thats why

each function adds +1 to the line_break_info variable to keep track

how many line breaks it is using*/

//main screen mesage

void greetings(int &line_break_info);

//Top header is the heading at very top of the screen

void top_header(int &line_break_info);

//This function handles the choice entered by the user

void handle_choice(int choice,int &line_break_info);

//To push...