1.11M Members

stack implemtation using link list

 
0
 

Hello,
I need some help writing code for a stack using link list implementation without using the STL. Basically what the stack would do is to convert an infix expression to postfix and then show the results of the operation. The stack should utilize a class not a struct. I'm at a loss right now and dont even know where to start. Any help would be great.

 
-1
 

>>I need some help writing code for a stack using link list implementation without using the STL
So your first task is to create a linked list implementation. Do you know
how to start ? Try it and come back.

 
0
 

Hello,
I need some help writing code for a stack using link list implementation without using the STL. Basically what the stack would do is to convert an infix expression to postfix and then show the results of the operation. The stack should utilize a class not a struct. I'm at a loss right now and dont even know where to start. Any help would be great.

below is what i have so far.

class Stack {
protected:
	Stack* stackTop;
   public:
      virtual void Push() = 0;
      virtual void Pop() = 0;
	  virtual bool Peek()= 0;	
      virtual bool isEmpty(void) const = 0;
};

class StackTypeChar : public Stack {
public:
	StackTypeChar (){stackTop = NULL; top = -1;}
	bool IsEmpty () const;
	void Push (char value);
	void Pop ();
	char Peek () const;
private:
	char top;


};



class StackTypeInt : public Stack {
public:
	StackTypeInt(){stackTop = NULL; top = -1;}
	bool IsEmpty () const { return top == -1;}
	void Push (int value);
	void Pop ();
	int Peek () const;
private:
	int top;
	
};


    

class ListStackClass: {
private:
      Stack* stackTop; 
	  
   };
public:
	StackTypeInt(){stackTop = NULL;}
        StackTypeChar(){stackTop = NULL;}
	bool IsEmpty () const;
	void Push ();
	void Pop ();
	bool Peek () const;

};

int main(){
	
StackTypeInt stack1;
StackTypeChar stack2;
 
-1
 

I guess you have never heard of templates. You can't use that code because it is an array-based stack implementation. You need to implement
an linked list based stack implementation. Do you know the basics
of a single linked list?

 
0
 

I kind of know how to do that but i'm not supposed to use the STL library. I'm supposed to write the stack implementation myself and i'm confused about how to embed the stack in the list class. i have taken the array stuff out of the code now.

 
0
 

I kind of know how to do that but i'm not supposed to use the STL library. I'm supposed to write the stack implementation myself and i'm confused about how to embed the stack in the list class. i have taken the array stuff out of the code now.

using templates is not part of the stl. Its part of C++. Anyways,
first create a linked list implementation. Have a Node class.
And use that Node class inside a linkedList class. Use the notion
of head and tail pointers. Do you know how to implement a linked list? After you get the linked list, creating a stack class will take you less than 5 minutes.

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article