i)Describe a class for stack objects on the heap,incl.the operations listed below?

and any other member data and member functions you consider necessary.

define operations to:
ii)pop a value off the stack
iii)push a value onto the stack
iv)Inspect the top of the stack without popping it
v)overload the insertion operator(<<) to print all the values on the stack leaving the stack unchanged
vi)give a brief main program which illustrates each of your operations.

Please use C++ programming language.

Answers:
I will not use C++ language, but I can help u with how to go about programming it.
First understand how a stack works. Draw it on paper, link a few nodes using arrows. Then add a new node. Delete a node and see how it works on paper. I did this when I was learning about linked lists, stacks and queues and it has helped me. The concepts become clear and coding a breeze.

Once you are done with this, design a class which will be your node. Make sure you have a pointer which is used to point to the next node in the stack. Have another class, the Stack, which has the implementations of all the operations listed. Also there will always be one pointer(lets call it the head) which points to the top of stack always. Lets go thru the listed operations

o Push---> get a new node. Assign the vales to its member variables. Set its next pointer to point to current top of stack(obtained from head). Set head to point to this new node. And you are done with Push operation!! Simple isnt it?Be careful when there are no nodes, ie and empty stack.

o Pop---->Get a temp pointer and set it to point to what head is pointing to.Set head to the next node from the current Top of stack. Then delete node pointed by temp. There you go, you have popped a value out of your stack.Again be careful when you have an empty stack.

o Display---> just get the value of data from the Top of stack (pointed to by head). Its that simple!

o Overload<<--->This is not a stack concept. Overlaod the operator and in the implementation run thru the stack(from head till last node) and print out the data of each node.

Make sure you check for boundary conditions like when there are no nodes initially. Or while popping when nodes arent present etc. You will have to use new and delete operations extensively in the case above. You could also settle for a simple array to act as you stack and have indices(int variables) to act as pointer, but I woldnt suggest that approach.

Sorry to disappoint you and not give you the code. I have written the code and learnt how to implement a stack. Now you have to do it, make mistakes, get a few sgementation faults to finally learn it. Have fun with it, its worth it :)

Other answers:
if(bStudent && bHomeworkQuestions)
{
return; // student needs to learn to do own coding
}


did you really expect someone to write all that code for you??? wow... I'm sorry for you. Learn the material it's well worth it! The journey is much more valuable than the destination.
  • how do i use the messenger chat or java chat? Why do i not have adult catagory on mY messenger chat list?
  • who can put pictures to disc like a slideshow with music?
  • hi, please if there any body know what is Windows CE setup file meane!!?
  • How long does it take for a attachment file to finish processing?
  • is there a way for my camera phone to send a jpeg file?
  • Which is the best software for 2d and 3d animation?
  • What kind of program do i have to learn to be able to create my own site..i curently own a yahoo group?
  • Help! I need help fixing a website for Firefox users!?
  • Anyone can help with .net speech enbaled application?
  • Backtrace of linux core dump with no debug info in it.?