Professional Documents
Culture Documents
ACKNOWLEDGEMNET:
1
MIT Polytechnic Pune Implement Stack Using Link list
Requirement:-
Sr. No. Name of Specification Quantity Remarks
Resources/
Material
2
MIT Polytechnic Pune Implement Stack Using Link list
3.0Action plan
and Final
Execution
6 Report generation 2012/2022 20/12/22 Roopesh
Nakul
7 Final submission 20/12/022 20/12/22
3
MIT Polytechnic Pune Implement Stack Using Link list
Aim:
Write a C Program to Implement a Stack Using Linked
List (Pointer).
Theory:
Linked List Implementation:
4
MIT Polytechnic Pune Implement Stack Using Link list
Algorithm:
1. Create a structure with an element (Element) and
a pointer (Next) that points to the next node in
the list.
2. Create a head pointer using the malloc function
and assign the resultant pointer variable to the
head pointer S.
3. In the Push operation, create a new node, called
TmpCell using the malloc function, assign the
new element X to TmpCell->Element, make
TmpCell point to the node that was previously
pointed to by the head pointer and make the head
pointer point to TmpCell by the statements:
TmpCell->Next=S->Next and S-
>Next=TmpCell.
4. In the Pop operation, store the node pointed to by
the head pointer in a pointer called FirstCell by
the statement FirstCell=S->Next. Then make the
head pointer point to the node next to FirstCell
by the statement S->Next=S->Next->Next. Then
free FirstCell.
5. In the Top operation, return the element pointed
to by the head pointers next node by the
statement S->Next-> Element.
5
MIT Polytechnic Pune Implement Stack Using Link list
Program:
#include<stdio.h>
#include<stdlib.h>
/* Node decleration */
struct node
int data;
};
void create();
void push();
void pop();
void display();
void main()
int ch;
//clrscr();
while(1)
6
MIT Polytechnic Pune Implement Stack Using Link list
scanf("%d",&ch);
switch(ch)
case 1:
create();
display();
break;
case 2:
push();
display();
break;
case 3:
pop();
display();
break;
case 4:
exit(0);
7
MIT Polytechnic Pune Implement Stack Using Link list
void create()
scanf("%d",&temp->data);
temp->link=NULL;
top=temp;
void push()
scanf("%d",&temp->data);
temp->link=top;
top=temp;
void pop()
8
MIT Polytechnic Pune Implement Stack Using Link list
if(top==NULL)
printf("\nSTACK IS EMPTY\n");
else
temp=top;
top=top->link;
free(temp);
void display()
printf("\n");
while(temp!=NULL)
9
MIT Polytechnic Pune Implement Stack Using Link list
printf("%d\n",temp->data);
10
MIT Polytechnic Pune Implement Stack Using Link list
Execution:
Input:
1 23 2 12 2 14 3 12
Output:
1.CREATE
2.PUSH
3.POP
4.EXIT
23
1.CREATE
2.PUSH
3.POP
4.EXIT
11
MIT Polytechnic Pune Implement Stack Using Link list
12
23
1.CREATE
2.PUSH
3.POP
4.EXIT
14
12
23
1.CREATE
2.PUSH
3.POP
12
MIT Polytechnic Pune Implement Stack Using Link list
4.EXIT
DELETED ELEMENT IS 14
12
23
1.CREATE
2.PUSH
3.POP
4.EXIT
1.CREATE
2.PUSH
3.POP
4.EXIT
13
MIT Polytechnic Pune Implement Stack Using Link list
14
MIT Polytechnic Pune Implement Stack Using Link list
15
MIT Polytechnic Pune Implement Stack Using Link list
16
MIT Polytechnic Pune Implement Stack Using Link list
17
MIT Polytechnic Pune Implement Stack Using Link list
18
MIT Polytechnic Pune Implement Stack Using Link list
19