Beruflich Dokumente
Kultur Dokumente
PROBLEMS ON STACK
Submitted in partial fulfilment of the
Requirements for the award of the Degree of
Bachelor of Technology
in
COMPUTER SCIENCE AND ENGINEERING
BY
A.Priyanka(170030041)
D.Manasa Bala Sai Krishanaja(170030300)
V.Prudvi Raj(170031331)
K.Wincent Paul(170030639)
K L University
Green Fields, Vaddeswaram, Guntur District-522 502
K L University
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
CERTIFICATE
This is to certify that this project based lab report entitled “STACK APPILICATIONS” is
bonafide work done by A.Priyanka(170030041),D.Manasa Bala Sai Krishnaja(170030300),
V.Prudvi Raj(170031331), K.Wincent Paul(170030639) in partial fulfilment of the
requirements for the award of degree in bachelor of technology in COMPUTER SCIENCE
AND ENGNEERING during the Academic year 2017-2018.
P.VENKATESWARA RAO
PROFESSOR
Project guide
P.YELLAMMA
(ASSISTANT PROFESSOR)
K L University
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
DECLARATION
We hereby declare that this project based lab report titled “PROBLEMS ON STACKS”has
been prepared by us in partial fulfilment of the requirements for the award of degree
“BACHELOR OF TECHNOLOGY in COMPUTER SCIENCE AND ENGNEERING”
during the Academic year 2018.
We also declare that this project based lab report is of our own efforts and it has not been
submitted to any other university for the award of any degree.
BY
A.Priyanka(170030041)
D.Manasa Bala Sai Krishanaja(170030300)
V.Prudvi Raj(170031331)
K.Wincent Paul(170030639)
ACKNOWLEDGEMENT
Our sincere thanks to P.VENKATESWARA RAO in the Lab for their outstanding support
throughout the project for the successful completion of the work.
We express our gratitude to,Head of the Department for Computer Science and Engineering for
providing us with adequate facilities, ways and means by which we are able to complete this
project based Lab.
We would like to place on record the deep sense of gratitude to the honourable Vice Chancellor,
K L University for providing the necessary facilities to carry the project based Lab.
Last, but not the least, we thank all Teaching and Non-Teaching Staff of our department and
especially my classmates and my friends for their support in the completion of our project based
Lab.
BY
A.Priyanka(170030041)
D.Manasa Bala Sai Krishanaja(170030300)
V.Prudvi Raj(170031331)
K.Wincent Paul(170030639)
CONTENTS
S.no content
1. ABSTRACT
2. INTRODUCTION
3. DESCRIPTION
4. CODE
5. OUTPUT
Abstract
INTRODUCTION:
The order in which elements come off a stack gives rise to its alternative name, LIFO (last
in, first out). Additionally, a peek operation may give access to the top without modifying the
stack. The name "stack" for this type of structure comes from the analogy to a set of physical
items stacked on top of each other, which makes it easy to take an item off the top of the stack,
while getting to an item deeper in the stack may require taking off multiple other items first .
Considered as a linear data structure, or more abstractly a sequential collection, the push and pop
operations occur only at one end of the structure, referred to as the top of the stack. This makes it
possible to implement a stack as a singly linked list and a pointer to the top element. A stack may
be implemented to have a bounded capacity. If the stack is full and does not contain enough
space to accept an entity to be pushed, the stack is then considered to be in an overflowstate. The
pop operation removes an item from the top of the stack.
Implementation:
A stack can be easily implemented either through an array or a linked list. What identifies the
data structure as a stack in either case is not the implementation but the interface: the user is only
allowed to pop or push items onto the array or linked list, with few other helper operations. The
following will demonstrate both implementations, using pseudocode.
A PUSH operation, in which a data item is placed at the location pointed to by the stack
pointer, and the address in the stack pointer is adjusted by the size of the data item;
A POP operation: a data item at the current location pointed to by the stack pointer is
removed, and the stack pointer is adjusted by the size of the data item.
ADVANTAGES
Better space utilization for large items.
Simple collision handling searching element
Deletion is quick and easy.
DISADVANTAGES
Storing the data in adjacent memory locations,as in linear probing,has
very good caching behavior.
DESCRIPTION:
MODULE- 1 :
1. Function: creates an empty stack.
2. Function: pushes an item onto the stack
3. Function: pops item on the top of the stack
4. Function: Retrieves data from the top of stack without changing the stack
5. Function: determines if a stack is empty
6. Function: determines if a stack is full
7. Function: Returns number of elements in stack
8. Function: destroyStack -releases all nodes to the heap
9. Function: Reverse elements,
10. Function: copy to other array if stack is half full
MODULE-2:
Stack Applications
1. Program: reverses a list of integers read from the keyboard by pushing them into a stack and
retrieving them one by one.
2. Program: reads an integer from the keyboard and prints its binary equivalent. It uses a stack to
reverse the order of 0s and 1s produced.
3. Program: reads a source program and parses it to make sure all opening-closing parentheses
are paired
4. Program: converts an infix formula to a postfix formula
5. Program: converts an infix formula to a prefix formula
6. Program: evaluates a postfix expression and returns its value.
MODULE -3:
1. Program: Convert prefix to postfix expression.
2. Program: Recursively determine the length of a prefix expression
3. Program: Recursive Fibonacci Series Arraymax, Binary
4. Program: Recursive Euclidean Algorithm for Greatest Common Divisor, Palindrome
5. Program: Recursive Towers of Hanoi, Powers Recursive
6. Goal-seeking application: One way to portray the problem is to lay out the steps in the form of
a graph that contains several alternate paths. Only one of the paths in the graph leads to a desired
goal.
MODULE-4:
Implementation of stack using two queues
1. Function: pushes an item onto the stack
2. Function: pops item on the top of the stack
3. Function: enqueue an item onto the queue
4. Function: dequeue item on the top of the queue
Implementation queue using two stacks
1. Function: enqueue an item onto the queue
2. Function: dequeue item on the top of the queue
3. Function: pushes an item onto the stack
4. Function: pops item on the top of the stack
SOURCE CODE:
#include<stdio.h>
#include<stdlib.h>
int capacity;
int size;
int *elements;
}Stack;
Stack *S;
S = (Stack *)malloc(sizeof(Stack));
S->size = 0;
S->capacity = maxElements;
return S;
int top=-1,stack[MAX];
void push();
void pop();
void display();
void main()
int ch;
printf("\n\n1.Push\n2.Pop\n3.Display\n4.Exit");
printf("\n\nEnter your choice(1-4):");
scanf("%d",&ch);
switch(ch)
case 1: push();
break;
case 2: pop();
break;
case 3: display();
break;
case 4: exit(0);
void push()
int val;
if(top==MAX-1)
printf("\nStack is full!!");
}
else
scanf("%d",&val);
top=top+1;
stack[top]=val;
void pop()
if(top==-1)
printf("\nStack is empty!!");
else
top=top-1;
void display()
{
int i;
if(top==-1)
printf("\nStack is empty!!");
else
printf("\nStack is...\n");
for(i=top;i>=0;--i)
printf("%d\n",stack[i]);
OUTPUT: