0
#include<iostream.h>
#include<string.h>
struct node
{
	node*next;
	int data;
};
class stack
{
private:node*top;node*top2;char c;
public:
	stack()
	{
		top=NULL;
		top2=NULL;
	}
	void push(char c)
	{
		if(top==NULL)
		{
			top=new node;
			top->data=c;
			top->next=NULL;
		}
		else
		{
			node*temp=top;
			temp->data=c;
			temp->next=top;
			top=temp;
		}
	}
	void pop()
	{
		node*temp=top;
		char x=temp->data;
		cout<<x;
		top=top->next;
		delete temp;
	}
};
void main()
{
	stack a;
	char f[10];
	cout<<"enter"<<endl;
	cin>>f;
	for(int i=0;i<10;i++)
	{
		a.push(f[i]);
	}
	for(int j=0;j<10;j++)
{
a.pop();
}
}

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by jonsca
0

One thing to consider:

else
{
	node*temp=top;

 } //where is temp at this point?  nowhere it's been destroyed

Small(er) stuff:
It should be #include <iostream> and #include <string> (the latter of which you don't really use in your program).
You need using namespace std; (or better yet using std::cout; using std::endl; , or qualify them with std:: in the body of your code).
Change data to char in your struct, have main returning an int (and then return one) and look into cin.get() (see here for a reference).

Edited by jonsca: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.