You are on page 1of 19

MIT Polytechnic Pune Implement Stack Using Link List

ACKNOWLEDGEMNET:

We have great pleasure and sense of satisfaction in


this micro-project report on “Implement Stack Using Link List
” as part of the curriculum of Diploma in Computer
Engineering. Being novice in the field of designing and
structuring in this micro-project, it could have been extremely
difficult for us to complete this micro project on our own. We
are very fortunate to be guided by people with vast and
resourceful experience in their respective field of work.
We express my sincere gratitude to our guide Prof.S.D.Kale
for her timely guidance, support and suggestions. Weare
also thankful for her sincere help and for making us
available all the facilities of the department. Without her
efforts and constant monitoring the micro-project and
documentation would not have been duly completed. Also,
we express our sincere thanks to Prof.M. khurpade(HOD
Computer Department), besides,we take this opportunity to
express our sincere gratitude to the Principal Dr.R.S.Kale
for providing a good environment and facilities to complete
this micro-project. We would also like to thank all my
colleagues who have directly or indirectly guided and
helped us in the preparation of this micro project.

1
MIT Polytechnic Pune Implement Stack Using Link list

Requirement:-
Sr. No. Name of Specification Quantity Remarks
Resources/
Material

1. Computer Any desktop/ One computer


system system for each
laptop with student
Linux
distribution
2. 1
Office Turbo C/C++
software
package
3. 1
Software
required

2
MIT Polytechnic Pune Implement Stack Using Link list

3.0Action plan

SR. NAME OF RESPONSIBLE


Details of Activity PLAN PLAN TEAMMEMBER
no SHORT FINISHING
DATE DATE
1 Searching for topic 6/12/2022 6/12/22 Nakul

2 Surviving information 6/12/2022 6/12/22 Kalpesh

3 Requirement Analysis 7/12/022 7/12/22 Vishal

4 Finalizing Layout 07/12/2022 7/12/22 Nakul

5 Generating Program 12/12/2022 12/12/22 Nakul

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:

• We go for a linked list implementation of a


stack rather than an array implementation
because of the run-time memory allocation
feature of linked lists.
• In this implementation, we make a head
pointer and make it point to the first created
node in the stack.
• Whenever a new node is pushed into the stack
we make the head pointer point to the new
node and the new node to point to the already
existing node that was pointed by the head
pointer.
• The popping of an element from the stack.
• The element that was inserted last would be
popped out first.
• So, the head pointer is now made to point to
the First Node, which was pointed by the
Second Node and the Second Node is freed.

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;

struct node *link; //to maintain the link other nodes

};

struct node *top,*temp;

void create();

void push();

void pop();

void display();

void main()

int ch;

//clrscr();

while(1)

printf("\n\n 1.CREATE \n 2.PUSH \n 3.POP \n 4.EXIT \n");

6
MIT Polytechnic Pune Implement Stack Using Link list

printf("\n ENTER YOUR CHOICE : ");

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

/* create function create the head node */

void create()

printf("\nENTER THE FIRST ELEMENT: ");

temp=(struct node *)malloc(sizeof(struct node));

scanf("%d",&temp->data);

temp->link=NULL;

top=temp;

void push()

printf("\nENTER THE NEXT ELEMENT: ");

temp=(struct node *)malloc(sizeof(struct node));

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;

printf("\nDELETED ELEMENT IS %d\n",top->data);

top=top->link;

free(temp);

/* display function visit the linked list from top to end */

void display()

temp=top; // bring the top to top position

printf("\n");

while(temp!=NULL)

9
MIT Polytechnic Pune Implement Stack Using Link list

printf("%d\n",temp->data);

temp=temp->link; // Now temp points the previous node in the list

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

ENTER YOUR CHOICE :

ENTER THE FIRST ELEMENT:

23

1.CREATE

2.PUSH

3.POP

4.EXIT

11
MIT Polytechnic Pune Implement Stack Using Link list

ENTER YOUR CHOICE :

ENTER THE NEXT ELEMENT:

12

23

1.CREATE

2.PUSH

3.POP

4.EXIT

ENTER YOUR CHOICE :

ENTER THE NEXT ELEMENT:

14

12

23

1.CREATE

2.PUSH

3.POP

12
MIT Polytechnic Pune Implement Stack Using Link list

4.EXIT

ENTER YOUR CHOICE :

DELETED ELEMENT IS 14

12

23

1.CREATE

2.PUSH

3.POP

4.EXIT

ENTER YOUR CHOICE :

1.CREATE

2.PUSH

3.POP

4.EXIT

13
MIT Polytechnic Pune Implement Stack Using Link list

ENTER YOUR CHOICE :

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

Rollno. Student Marks out of 6 our Marks out of Total


Name performance/Group 4 for Marks
activity performance
in oral (Total 10)
/presentation
74 Nakul
80 Roopesh
81 Kalpesh
109 Vishal

Signature of Project Guide

Project Guide: J.V.Kachare

18
MIT Polytechnic Pune Implement Stack Using Link list

19

You might also like