my code

Reham ALblihed

Stack Using Linked List
by Reham ALblihed

- push
- pop
- is empty
- print

Snippet options

Download: Download snippet as stack-using-linked-list.cpp.
Copy snippet: For this you need a free my code account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

using namespace std;

struct node{
	int info;
	node *next;

class stack{
	node *top;
		top = NULL;

	bool isempty();
	void push(int);
	int pop();
	void traverese();


bool stack::isempty(){
	if (top == NULL)
		return true;
		return false;

void stack::push(int item){
	node *nw = new node;
	nw->info = item;
		nw->next = top;
		top = nw;
int stack::pop(){
	if (isempty()){
		cout << "  ";
		return -1;
		int t = top->info;
		node *p = top;
		top = top->next;
		delete p;
		return t;

void stack::traverese(){

	node *curr;
	for (curr = top; curr; curr = curr->next){
		cout << curr->info;
	cout << endl;

int main(){
	int item;
	int size;
	stack x;
	cout << i;
	cout << endl;
	cout << "Enter element size";
	cin >> size;
	for (int i = 0; i < size; i++){
		cin >> item;


Create a free my code account now.

my code is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.