v karthik
implementation of stacks using linked lists in c++
2 Answer(s)      4 years and 11 months ago
Posted in : Java Beginners

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

Ads

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, 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
lists
lists  how to implement lists by using array
implementation object in C
implementation object in C  how to create and implement an object in C
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
stack using linked list
stack using linked list  how to implement stack using linked list
c++ garbage collection implementation
c++ garbage collection implementation  How to implement the garbage collection program in C
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
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
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
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... to print out the results of the query: for ( Car c : cars
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
Java Stacks - Java Beginners
. Write the specification and implementation of the methods: o Adds... the implementation of the operation process prescription
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
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
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
linked list
linked list  program for single linked list
creation button using objective c
creation button using objective c  creation button using objective c
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
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
C++
C++  Describe the principle advantages of deploying a linked list versus a static array when implementing a Queue or a Stack
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
creating dropdown lists in jsp
creating dropdown lists in jsp  i want to create two dropdown list which are dependent that is the first box choice have to evaluate the second boxs options