SlideShare una empresa de Scribd logo
1 de 13
BRAINWARE
UNIVERSITY
STACK
NAME : RITU SARKAR
STUDENT CODE : BWU/BTD/21/010
STREAM : B.TECH CSE(DS)
COURSE : DATA STRUCTURE & ALGORITHMS
COURSE CODE : ESCD302
CONTENT
• Introduction
• What is Stack
• Properties of Stack
• Example
• Representation of Stack
• Operations of Stack
• Conditions of Stack
• Stack Implementation Using Array
• Stack Implementation Using Linked List
• Applications of Stack
• References
2
BWU/BTD/21/010
INTRODUCTION
Data Structure is the representation of the logical relationship between individual elements of data. In Computer
Science, Data Structure is defined as a mathematical or logical model of organizing the data items into computer
memory in such a way that they can be used efficiently.The purpose of studying data structure is to learn how to
organize data into memory so that it can be accessed quickly and conveniently.
Data
Structure
Primitive
Int Float Char Pointer
Non-
Primitive
Linear
Sequential
Array Stack Queue
Linked
Linked
List
Linked
Stack
Linked
Queue
Non-
Linear
Graph Tree
3
BWU/BTD/21/010
WHAT IS STACK
A stack is one of the most important and useful non-primitive linear data structure in computer science. Real-life
examples of the stack are a stack of books, a stack of plates, a stack of cards, a stack of coins, etc.
Definition: A stack is a sequential collection of elements into which new elements are inserted and from which,
elements are deleted only at one end.
PROPERTIES OF STACK
 It is an abstract data type.
 It is a First-In-First-Out (FIFO) data structure.
 It can be implemented using array as well as linked list.
 It has two main operations – Push ( insertion ) & Pop ( deletion ).
 In stack insertion and deletion is done at a single end that is a specific position, and
the position is called top.
A stack is declared as –
𝑑𝑎𝑡𝑎𝑡𝑦𝑝𝑒 𝑠𝑡𝑎𝑐𝑘𝑛𝑎𝑚𝑒[𝑠𝑖𝑧𝑒]
𝑖𝑛𝑡 𝑠𝑡𝑎𝑐𝑘 6
4
BWU/BTD/21/010
EXAMPLE
OPERATIONS OF STACK
There are two main operations in stack data structure –
 Creation Operation
 IsemptyOperation
 Isfull Operation
 Push Operations
 Pop Operations
 Peek Operation
The stack can be represented using the following structure:
𝑠𝑡𝑟𝑢𝑐𝑡 𝑆𝑇𝐴𝐶𝐾
{
𝑖𝑛𝑡 𝑎 𝑀𝐴𝑋𝑆𝐼𝑍𝐸 ;
𝑖𝑛𝑡 𝑡𝑜𝑝;
};
REPRESENTATION OF STACK
5
BWU/BTD/21/010
Operation Description
Creation This operation creates a stack and initializes the stack.
Isempty This operation checks whether the stack empty or not.
Isfull This operation checks whether the stack full or not.
Insertion (Push) This operation inserts an item only at the top of the stack when the stack is
not full.
Deletion (Pop) This operation deletes an item only at the top of the stack when the stack is
not empty.
Peek This operation returns the value of the top of the stack without removing
the element from the stack.
• Top = integer variable that points to the top location of the stack.
• Top = -1 ( If there is no data in the stack )
6
BWU/BTD/21/010
Ex : int stack, push 10
push 20
pop
push 55
push 50
pop ; What is the top & the top value ?
⇒
10
20
10 10
55
10
50
55
10
55
10
5
4
3
2
1
0
5
4
3
2
1
0
5
4
3
2
1
0
5
4
3
2
1
0
5
4
3
2
1
0
5
4
3
2
1
0
5
4
3
2
1
0
push 10
→ → → → → →
push 20 pop push 55 push 50 pop
So, the top is 1 and the top value is 55.
7
BWU/BTD/21/010
CONDITIONS OF STACK
There are two conditions in stack –
 Overflow Condition :
𝑖𝑓 (𝑇𝑜𝑝 == 𝑀𝑎𝑥𝑖𝑚𝑢𝑚 𝑆𝑖𝑧𝑒)
(𝑇𝑜𝑝 ≥ 𝑛)
When we can not insert any data as the stack is
filled, the state is called overflow condition.
11
66
55
43
33
22
 Underflow Condition :
𝑖𝑓 (𝑇𝑜𝑝 == −1)
When we can not delete any data as the stack is empty, the
state is called underflow condition.
5
4
3
2
1
0
5
4
3
2
1
0
push 10 pop
Ex :
Ex :
8
BWU/BTD/21/010
STACK IMPLEMENTATION USING ARRAY
The array can be used to implement a stack of fixed size.
 Algorithm to insert (push) onto the stack :
Algorithm : PUSH (STACK, ITEM)
[STACK is an array of MAXSIZE and ITEM is an item to be
pushed onto stack]
1. [Check for stack overflow]
IfTOP = MAXSIZE - 1 then
a) Print: Overflow
b) Return
2. ELSE [Increase top by 1]
SetTOP =TOP + 1
3. [Insert item in new top position]
Set STACK[TOP] = ITEM
4. Return
 Algorithm to deletes (pop) the top element from the stack
Algorithm : POP (STACK, ITEM)
[STACK is an array and ITEM is an item to be popped from
stack]
1. [Check for stack underflow]
IfTOP = -1 then
a) Print: Underflow
b) Return
2. ELSE[Assign top element to item]
Set ITEM = STACK[TOP]
3. [Decrease top by 1]
SetTOP =TOP - 1
4. Return
9
BWU/BTD/21/010
STACK IMPLEMENTATION USING ARRAY
The array can be used to implement a stack of fixed size.
 Algorithm of the push operation using linked list :
Algorithm : PUSH (HEAD, ITEM)
[HEAD is a pointer to the first node and ITEM is an item to
be pushed onto stack]
1. [Create the new node]
Allocate memory for NEW node
2. If NEW = NULL then
i) Print: Out of memory
ii) Return
3. Set NEW→DATA = ITEM
4. Set NEW→LINK = HEAD
5. Set HEAD = NEW
6. Return
 Algorithm of pop operation using linked list :
Algorithm : POP (HEAD, ITEM)
[HEAD is a pointer to the first node and ITEM is an item to be
popped from stack]
1. [Whether List is empty]
If HEAD = NULL then
i) Print: Stack is underflow
ii) Return
2. ITEM = HEAD→DATA
3. Set P = HEAD
4. HEAD = HEAD→LINK
5. Set P→LINK = NULL
6. De-allocate memory for node P
7. Return
10
BWU/BTD/21/010
APPLICATIONS OF STACK
The stack is a very useful data structure. Most of the modern computers and microprocessor provide an inbuilt
hardware stack. Even there are stack-oriented computer architectures.
Stacks are used -
 To implement recursive function call and processing of function calls
such as passing arguments.
 Evaluation of Arithmetic expressions.
 To simulate recursion.
 To implement scope rule and block structure.
 To develop Compilers, System programs,Operating Systems and in
many elegant application algorithms.
 To implement different algorithms, Depth first search, Quicksort,
Mergesort etc.
11
BWU/BTD/21/010
REFERENCES
 Class notes
 AText Book – Data Structure & Algorithm with C
– By Debdutta Pal, Suman Halder
12
BWU/BTD/21/010
THANK YOU
Have A Great Day !
13
BWU/BTD/21/010
Ritu Sarkar
bwubtd21010@gmail.ac.in

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Stacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti AroraStacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti Arora
 
Abstract Data Types
Abstract Data TypesAbstract Data Types
Abstract Data Types
 
Queue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListQueue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked List
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
Stack
StackStack
Stack
 
Heap and heapsort
Heap and heapsortHeap and heapsort
Heap and heapsort
 
Java constructors
Java constructorsJava constructors
Java constructors
 
Stacks
StacksStacks
Stacks
 
14 file handling
14 file handling14 file handling
14 file handling
 
Stack
StackStack
Stack
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 
Java IO
Java IOJava IO
Java IO
 
Data Structure and Algorithms Heaps and Trees
Data Structure and Algorithms Heaps and TreesData Structure and Algorithms Heaps and Trees
Data Structure and Algorithms Heaps and Trees
 
Ajax
AjaxAjax
Ajax
 
Simple Java Programs
Simple Java ProgramsSimple Java Programs
Simple Java Programs
 
input/ output in java
input/ output  in javainput/ output  in java
input/ output in java
 
Inline Functions and Default arguments
Inline Functions and Default argumentsInline Functions and Default arguments
Inline Functions and Default arguments
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
Heaps
HeapsHeaps
Heaps
 
Merge sort
Merge sortMerge sort
Merge sort
 

Similar a Stack in C.pptx

Presentation topic is stick data structure
Presentation topic is stick data structurePresentation topic is stick data structure
Presentation topic is stick data structureAizazAli21
 
Data structure , stack , queue
Data structure , stack , queueData structure , stack , queue
Data structure , stack , queueRajkiran Nadar
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queuePulkitmodi1998
 
Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9Getachew Ganfur
 
Stacks & Queues
Stacks & QueuesStacks & Queues
Stacks & Queuestech4us
 
Stack and its applications
Stack and its applicationsStack and its applications
Stack and its applicationsAhsan Mansiv
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueBalwant Gorad
 
Chapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdfChapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdfGirT2
 
Stacks Data structure.pptx
Stacks Data structure.pptxStacks Data structure.pptx
Stacks Data structure.pptxline24arts
 

Similar a Stack in C.pptx (20)

Presentation topic is stick data structure
Presentation topic is stick data structurePresentation topic is stick data structure
Presentation topic is stick data structure
 
04 stacks
04 stacks04 stacks
04 stacks
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
 
Data structure , stack , queue
Data structure , stack , queueData structure , stack , queue
Data structure , stack , queue
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queue
 
LEC3-DS ALGO(updated).pdf
LEC3-DS  ALGO(updated).pdfLEC3-DS  ALGO(updated).pdf
LEC3-DS ALGO(updated).pdf
 
Data structure stack&queue basics
Data structure stack&queue   basicsData structure stack&queue   basics
Data structure stack&queue basics
 
Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9
 
Rana Junaid Rasheed
Rana Junaid RasheedRana Junaid Rasheed
Rana Junaid Rasheed
 
Stacks & Queues
Stacks & QueuesStacks & Queues
Stacks & Queues
 
Stack and its applications
Stack and its applicationsStack and its applications
Stack and its applications
 
Stack and its operations
Stack and its operationsStack and its operations
Stack and its operations
 
DSA Lab Manual C Scheme.pdf
DSA Lab Manual C Scheme.pdfDSA Lab Manual C Scheme.pdf
DSA Lab Manual C Scheme.pdf
 
Algo>Stacks
Algo>StacksAlgo>Stacks
Algo>Stacks
 
104332 sri vidhya eng notes
104332 sri vidhya eng notes104332 sri vidhya eng notes
104332 sri vidhya eng notes
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
 
Chapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdfChapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdf
 
Stacks Data structure.pptx
Stacks Data structure.pptxStacks Data structure.pptx
Stacks Data structure.pptx
 
Stack - Operations and Applications
Stack - Operations and ApplicationsStack - Operations and Applications
Stack - Operations and Applications
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
 

Último

CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 

Último (20)

CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 

Stack in C.pptx

  • 1. BRAINWARE UNIVERSITY STACK NAME : RITU SARKAR STUDENT CODE : BWU/BTD/21/010 STREAM : B.TECH CSE(DS) COURSE : DATA STRUCTURE & ALGORITHMS COURSE CODE : ESCD302
  • 2. CONTENT • Introduction • What is Stack • Properties of Stack • Example • Representation of Stack • Operations of Stack • Conditions of Stack • Stack Implementation Using Array • Stack Implementation Using Linked List • Applications of Stack • References 2 BWU/BTD/21/010
  • 3. INTRODUCTION Data Structure is the representation of the logical relationship between individual elements of data. In Computer Science, Data Structure is defined as a mathematical or logical model of organizing the data items into computer memory in such a way that they can be used efficiently.The purpose of studying data structure is to learn how to organize data into memory so that it can be accessed quickly and conveniently. Data Structure Primitive Int Float Char Pointer Non- Primitive Linear Sequential Array Stack Queue Linked Linked List Linked Stack Linked Queue Non- Linear Graph Tree 3 BWU/BTD/21/010
  • 4. WHAT IS STACK A stack is one of the most important and useful non-primitive linear data structure in computer science. Real-life examples of the stack are a stack of books, a stack of plates, a stack of cards, a stack of coins, etc. Definition: A stack is a sequential collection of elements into which new elements are inserted and from which, elements are deleted only at one end. PROPERTIES OF STACK  It is an abstract data type.  It is a First-In-First-Out (FIFO) data structure.  It can be implemented using array as well as linked list.  It has two main operations – Push ( insertion ) & Pop ( deletion ).  In stack insertion and deletion is done at a single end that is a specific position, and the position is called top. A stack is declared as – 𝑑𝑎𝑡𝑎𝑡𝑦𝑝𝑒 𝑠𝑡𝑎𝑐𝑘𝑛𝑎𝑚𝑒[𝑠𝑖𝑧𝑒] 𝑖𝑛𝑡 𝑠𝑡𝑎𝑐𝑘 6 4 BWU/BTD/21/010
  • 5. EXAMPLE OPERATIONS OF STACK There are two main operations in stack data structure –  Creation Operation  IsemptyOperation  Isfull Operation  Push Operations  Pop Operations  Peek Operation The stack can be represented using the following structure: 𝑠𝑡𝑟𝑢𝑐𝑡 𝑆𝑇𝐴𝐶𝐾 { 𝑖𝑛𝑡 𝑎 𝑀𝐴𝑋𝑆𝐼𝑍𝐸 ; 𝑖𝑛𝑡 𝑡𝑜𝑝; }; REPRESENTATION OF STACK 5 BWU/BTD/21/010
  • 6. Operation Description Creation This operation creates a stack and initializes the stack. Isempty This operation checks whether the stack empty or not. Isfull This operation checks whether the stack full or not. Insertion (Push) This operation inserts an item only at the top of the stack when the stack is not full. Deletion (Pop) This operation deletes an item only at the top of the stack when the stack is not empty. Peek This operation returns the value of the top of the stack without removing the element from the stack. • Top = integer variable that points to the top location of the stack. • Top = -1 ( If there is no data in the stack ) 6 BWU/BTD/21/010
  • 7. Ex : int stack, push 10 push 20 pop push 55 push 50 pop ; What is the top & the top value ? ⇒ 10 20 10 10 55 10 50 55 10 55 10 5 4 3 2 1 0 5 4 3 2 1 0 5 4 3 2 1 0 5 4 3 2 1 0 5 4 3 2 1 0 5 4 3 2 1 0 5 4 3 2 1 0 push 10 → → → → → → push 20 pop push 55 push 50 pop So, the top is 1 and the top value is 55. 7 BWU/BTD/21/010
  • 8. CONDITIONS OF STACK There are two conditions in stack –  Overflow Condition : 𝑖𝑓 (𝑇𝑜𝑝 == 𝑀𝑎𝑥𝑖𝑚𝑢𝑚 𝑆𝑖𝑧𝑒) (𝑇𝑜𝑝 ≥ 𝑛) When we can not insert any data as the stack is filled, the state is called overflow condition. 11 66 55 43 33 22  Underflow Condition : 𝑖𝑓 (𝑇𝑜𝑝 == −1) When we can not delete any data as the stack is empty, the state is called underflow condition. 5 4 3 2 1 0 5 4 3 2 1 0 push 10 pop Ex : Ex : 8 BWU/BTD/21/010
  • 9. STACK IMPLEMENTATION USING ARRAY The array can be used to implement a stack of fixed size.  Algorithm to insert (push) onto the stack : Algorithm : PUSH (STACK, ITEM) [STACK is an array of MAXSIZE and ITEM is an item to be pushed onto stack] 1. [Check for stack overflow] IfTOP = MAXSIZE - 1 then a) Print: Overflow b) Return 2. ELSE [Increase top by 1] SetTOP =TOP + 1 3. [Insert item in new top position] Set STACK[TOP] = ITEM 4. Return  Algorithm to deletes (pop) the top element from the stack Algorithm : POP (STACK, ITEM) [STACK is an array and ITEM is an item to be popped from stack] 1. [Check for stack underflow] IfTOP = -1 then a) Print: Underflow b) Return 2. ELSE[Assign top element to item] Set ITEM = STACK[TOP] 3. [Decrease top by 1] SetTOP =TOP - 1 4. Return 9 BWU/BTD/21/010
  • 10. STACK IMPLEMENTATION USING ARRAY The array can be used to implement a stack of fixed size.  Algorithm of the push operation using linked list : Algorithm : PUSH (HEAD, ITEM) [HEAD is a pointer to the first node and ITEM is an item to be pushed onto stack] 1. [Create the new node] Allocate memory for NEW node 2. If NEW = NULL then i) Print: Out of memory ii) Return 3. Set NEW→DATA = ITEM 4. Set NEW→LINK = HEAD 5. Set HEAD = NEW 6. Return  Algorithm of pop operation using linked list : Algorithm : POP (HEAD, ITEM) [HEAD is a pointer to the first node and ITEM is an item to be popped from stack] 1. [Whether List is empty] If HEAD = NULL then i) Print: Stack is underflow ii) Return 2. ITEM = HEAD→DATA 3. Set P = HEAD 4. HEAD = HEAD→LINK 5. Set P→LINK = NULL 6. De-allocate memory for node P 7. Return 10 BWU/BTD/21/010
  • 11. APPLICATIONS OF STACK The stack is a very useful data structure. Most of the modern computers and microprocessor provide an inbuilt hardware stack. Even there are stack-oriented computer architectures. Stacks are used -  To implement recursive function call and processing of function calls such as passing arguments.  Evaluation of Arithmetic expressions.  To simulate recursion.  To implement scope rule and block structure.  To develop Compilers, System programs,Operating Systems and in many elegant application algorithms.  To implement different algorithms, Depth first search, Quicksort, Mergesort etc. 11 BWU/BTD/21/010
  • 12. REFERENCES  Class notes  AText Book – Data Structure & Algorithm with C – By Debdutta Pal, Suman Halder 12 BWU/BTD/21/010
  • 13. THANK YOU Have A Great Day ! 13 BWU/BTD/21/010 Ritu Sarkar bwubtd21010@gmail.ac.in