implementation of stacks using linked lists in c++

implementation of stacks using linked lists in c++

how to implementation of stacks using linked lists in c++

View Answers

January 7, 2012 at 11:19 AM

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
struct node{
    int data;
    struct node *link;
    };
    struct node *top=NULL,*temp;
    void main(){
    int choice,data; 
    clrscr();  
    while(1){
    printf("\n1.Push\n2.Pop\n3.Display\n4.Exit\n");
    printf("\nEnter ur choice:");    
    scanf("%d",&choice);   
    switch(choice){  
        case 1:  
        temp=(struct node *)malloc(sizeof(struct node)); 
        printf("Enter a node data :"); 
        scanf("%d",&data); 
        temp->data=data;  
        temp->link=top; 
        top=temp;   
        break;    
        case 2:   
        if(top!=NULL){
        printf("The poped element is %d",top->data); 
        top=top->link; 
        }          
        else{
        printf("\nStack Underflow");
        }
        break;
        case 3:
        temp=top;
        if(temp==NULL){
        printf("\nStack is empty\n");
        }
        while(temp!=NULL){
        printf("->%d->",temp->data);
        temp=temp->link;
        }
        break;
        case 4:
        exit(0);
        }
      }
    }

January 7, 2012 at 11:21 AM

#include<stdio.h>
#include<malloc.h>

#define maxsize 10
void push();
void pop();
void display();

struct node{
int info;
struct node *link;
}
*start=NULL, *new,*temp,*p;
typedef struct node N;
main(){
int ch,a;
do{
printf("\t\t\tLinked stack");
printf("\n 1.Push");
printf("\n 2.Pop");
printf("\n 3.Display");
printf("\n 4.Exit");
printf("\n Enter your choice : ");
scanf("%d",&ch);
switch(ch){
case 1:
push();
break;

case 2:
pop();
break;

case 3:
display();
break;

case 4:
exit(0);
default:

printf("\nInvalid choice");
break;
}
}
while(ch<=3);
}
void push(){
new=(N*)malloc(sizeof(N));
printf("\nEnter the item : ");
scanf("%d",&new->info);
new->link=NULL;
if(start==NULL)
start=new;
else{
p=start;
while(p->link!=NULL)
p=p->link;
p->link=new;
}
}
void pop(){
if(start==NULL)
printf("\nStack is empty");
else if(start->link==NULL){
printf("\nThe deleted element is : %d",start->info);
free(start);
start=NULL;
}
else{
p=start;
while(p->link!=NULL){
temp=p;
p=p->link;
}
printf("\nDeleted element is : %d\n", p->info);
temp->link=NULL;
free(p);
}
}
void display(){
if(start==NULL)
printf("\nStack is empty");
else{
printf("\nThe elements are : ");
p=start;
while(p!=NULL){
printf("%d",p->info);
p=p->link;
}
printf("\n");
}
}









Related Tutorials/Questions & Answers:
implementation of stacks using linked lists in c++
implementation of stacks using linked lists in c++  how to implementation of stacks using linked lists in c++   #include<stdio.h> #include<stdlib.h> #include<conio.h> struct node{ int data
Linked Lists in C
Linked Lists in C  Hi all, I have a project to be implemented in C... help. Thank you in advance. Write a C program for managing car parts store. The treatment is done in a linked list. The application works on the command line
Advertisements
linked lists implementation - Java Beginners
linked lists implementation   1. Assume a programmer wanted to change the ADT of a list by adding the method: public boolean RemoveFirstLast..., there are no preconditions. Write the code for the method for a linked implementation (without tail
linked lists
linked lists  write a program to create a circular linked list in java and perform operations on it?   import java.util.*; public class CircularLinkedList<E> { private Entry<E> head; private Entry<
Concatenate two linked lists
Concatenate two linked lists  hello, How to concatenate two linked lists?   hii,ADS_TO_REPLACE_1 You can change null pointer of the first linked list to point the header of the second linked list
Linked list implementation
Linked list implementation  How to create linkedlist by using array in java? and also How to manipulate
Queue implementation using linked list.
Description: The advantage of using linked list is that there is no size limit. The size of queue grow and shrink as per insertion and deletion takes place. Code: # include <stdio.h> # include <stdlib.h> struct node
stack using linked list
stack using linked list  how to implement stack using linked list
implementation object in C
implementation object in C  how to create and implement an object in C
c++ garbage collection implementation
c++ garbage collection implementation  How to implement the garbage collection program in C
lists
lists  how to implement lists by using array
Java Convert decimal to binary using Stacks
Java Convert decimal to binary using Stacks In this section, you will learn how to convert decimal into binary using stacks. You all are aware of Stacks... operation removes an item from the top of the list. Using these operations, we
Multiplication of two polynomials using linked list in java
Multiplication of two polynomials using linked list in java  I am doing a program "Multiplication of two polynomials using linked list in java... for polynomial linked list import java.util.Scanner; class Node { public int
write a java pogram to add elements to linked list using keyboard and display it
write a java pogram to add elements to linked list using keyboard and display it  write a java pogram to add elements to linked list using keyboard and display
oopengl on3d using c/c++ - Development process
oopengl on3d using c/c++  sir i want a programs on opengl in 3d using c/c++ language give me new one sir
JDBC4.0-Dataset implementation of SQL using Annotations
JDBC4.0-Dataset implementation of SQL using Annotations An annotation... parameters ,by using the Generics and metadata APIs.We don't need to write... c : cars) { System.out.println(" car id=" + c.getId() + "
Calculate Entropy using C++
Calculate Entropy using C++  # include <iostream> # include <cmath> using namespace std; int main() { float S0,S1,S2,S3; float Hs,Hs3; float
Circular queue implementation using array.
How to create a Student data base using Linked List in java
How to create a Student data base using Linked List in java  I want a program by using linked list in java. The data stored must... Record2 sandhya 22 5apr By using linked list I hve
creation button using objective c
creation button using objective c  creation button using objective c
Array Implementation in C
Array Implementation in C Code: #include<stdio.h> #include<conio.h... are : \n"); display(size,5); } void read(int c[],int i) { int j; for(j=0;j<i;j++) scanf("%d",&c[j]); fflush(stdin
C++
C++  Describe the principle advantages of deploying a linked list versus a static array when implementing a Queue or a Stack
ModuleNotFoundError: No module named 'stacks'
ModuleNotFoundError: No module named 'stacks'  Hi, My Python... 'stacks' How to remove the ModuleNotFoundError: No module named 'stacks'... to install padas library. You can install stacks python with following command
stacks in java - Java Beginners
stacks in java  i am doing a program that i have to finish it before monday so i only have tomorow to finish it. it about the stacks im designing... is within range) * && 0<=i=Card.JACK){ Card move=columns[c
How to print the following output using c program
How to print the following output using c program  1) 4 3 4 2 3 4 1 2 3 4 2) A B C D E F G H I J
linked list
linked list  program for single linked list
Online exam using c# and SQL server
Online exam using c# and SQL server  hello, i'm making the (window based)online examination system using C#.net and SQL SERVER. my database is stored on server. my question is: if during the examination server gets failed
Queue implementation using array.
Description: In this tutorial you will see how to implement queue using array and queue insert & delete operations. Code: #include <stdio.h> #define MAX 5 #include <stdlib.h> void insert(int queue[], int *rear
Linked list
Linked list  what is difference btw linked list in datastructure and linked list in java
Linked List
Linked List  public class Computer{ private int computerNumber... in the following logical linked list represents Computer Number. 76(head) 98 54...? to ?66?. The segment should also display the new contents of the linked list
linked list
linked list  hi i have basal problem what is the linked list
Making 301 redirection by using <c:redirect>
Making 301 redirection by using   How can i set the status as 301 when using tag? When i use , I am able to redirect to the desired URL (here, Google page) but I get 302 as the status of redirect. I need this status as 301. Any
linked list
linked list   how to write a program using a linked list, that will prompt a user to enter 10 names and display them in reverse   import java.util.*; class LinkedListExample { public static void main(String[] args
linked list
linked list  Hi i have a problem with linked list ! how and where i can use linked list? please give me some example.   Please visit...://www.roseindia.net/java/beginners/linked-list-demo.shtml
ModuleNotFoundError: No module named 'python-stacks'
ModuleNotFoundError: No module named 'python-stacks'  Hi, My... 'python-stacks' How to remove the ModuleNotFoundError: No module named 'python-stacks' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'stacks-image'
ModuleNotFoundError: No module named 'stacks-image'  Hi, My Python... 'stacks-image' How to remove the ModuleNotFoundError: No module named 'stacks-image' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'stacks-page'
ModuleNotFoundError: No module named 'stacks-page'  Hi, My Python... 'stacks-page' How to remove the ModuleNotFoundError: No module named 'stacks-page' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'stacks-snippet'
ModuleNotFoundError: No module named 'stacks-snippet'  Hi, My... named 'stacks-snippet' How to remove the ModuleNotFoundError: No module named 'stacks-snippet' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'stacks_summary'
ModuleNotFoundError: No module named 'stacks_summary'  Hi, My... named 'stacks_summary' How to remove the ModuleNotFoundError: No module named 'stacks_summary' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'stacks-textblock'
ModuleNotFoundError: No module named 'stacks-textblock'  Hi, My... named 'stacks-textblock' How to remove the ModuleNotFoundError: No module named 'stacks-textblock' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'stacks-twitter'
ModuleNotFoundError: No module named 'stacks-twitter'  Hi, My... named 'stacks-twitter' How to remove the ModuleNotFoundError: No module named 'stacks-twitter' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'stacks-contentgroup'
ModuleNotFoundError: No module named 'stacks-contentgroup'  Hi, My... named 'stacks-contentgroup' How to remove the ModuleNotFoundError: No module named 'stacks-contentgroup' error? Thanks   Hi
ModuleNotFoundError: No module named 'stacks-embed'
ModuleNotFoundError: No module named 'stacks-embed'  Hi, My Python... 'stacks-embed' How to remove the ModuleNotFoundError: No module named 'stacks-embed' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'stacks-featuredlink'
ModuleNotFoundError: No module named 'stacks-featuredlink'  Hi, My... named 'stacks-featuredlink' How to remove the ModuleNotFoundError: No module named 'stacks-featuredlink' error? Thanks   Hi
ModuleNotFoundError: No module named 'stacks-image'
ModuleNotFoundError: No module named 'stacks-image'  Hi, My Python... 'stacks-image' How to remove the ModuleNotFoundError: No module named 'stacks-image' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'stacks-page'
ModuleNotFoundError: No module named 'stacks-page'  Hi, My Python... 'stacks-page' How to remove the ModuleNotFoundError: No module named 'stacks-page' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'stacks-snippet'
ModuleNotFoundError: No module named 'stacks-snippet'  Hi, My... named 'stacks-snippet' How to remove the ModuleNotFoundError: No module named 'stacks-snippet' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'stacks_summary'
ModuleNotFoundError: No module named 'stacks_summary'  Hi, My... named 'stacks_summary' How to remove the ModuleNotFoundError: No module named 'stacks_summary' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'stacks-textblock'
ModuleNotFoundError: No module named 'stacks-textblock'  Hi, My... named 'stacks-textblock' How to remove the ModuleNotFoundError: No module named 'stacks-textblock' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'stacks-twitter'
ModuleNotFoundError: No module named 'stacks-twitter'  Hi, My... named 'stacks-twitter' How to remove the ModuleNotFoundError: No module named 'stacks-twitter' error? Thanks   Hi, In your python

Ads