SlideShare a Scribd company logo
PRESENTATION TOPIC
IS STICK DATA
STRUCTURE
PRESENTED BY: AIZAZ ALI
BSCS 3RD SEMESTER GPGC LANDIKOTAL
PRESENTED TO: SIR MR. MUHAMMAD NISAR SAIB
Stick definition
Stick operations , pop, push,
Example of stick
Implementation of stack as an array and
as linklist
References for study and objects
Stack definition :-
A stack is a linear data structure that can be accessed only at one of its ends for
storing and retrieving data. Such a stack resembles a stack of trays in a cafeteria:
new
trays are put on the top of the stack and taken off the top. The last tray put on
stack is the first tray removed from the stack.
Or
A stack is a list of homogenous elements in which the addition and deletion of
elements
occurs only at one end, called the top of the stack.
Or
A data structure in which the elements are added and removed from one end
Example no 1
FIGURE 1.1 An example of adding numbers 592 and 3,784 using stacks.
Now that you know what a stack is, let us see what kinds of operations can be
performed on a stack. Because new items can be added to the stack, we can
perform the add operation, called push, to add an element onto the stack.
Similarly, because the top item can be retrieved and/or removed from the stack,
we can perform the operation top to retrieve the top element of the stack, and
the operation pop to remove the top element from the stack.
The push, top, and pop operations work as follows: Suppose there are boxes
lying on the floor that need to be stacked on a table. Initially, all of the boxes
are on the floor and the stack is empty. (See Figure 7-2.)
First we push box A onto the stack. After the push operation, the stack is as shown in
Figure 7-3(a).
Example 2:- a series of the executed on a
stack
Presentation topic is stick data structure
Array:-
The array implementation aims to create an array where the first element (usually at the zero-
offset) is the bottom.
That is, array[0] is the first element pushed onto the stack and the last element popped off. The
program must
keep track of the size, or the length of the stack. The stack itself can therefore be effectively
implemented as a
two-element structure in C:
typedef struct {
size_t size;
int items[STACKSIZE];
} STACK;
void push(STACK *ps, int x)
{
if (ps->size == STACKSIZE) {
fputs("Error: stack overflown", stderr);
abort();
} else
ps->items[ps->size++] = x;
}
int pop(STACK *ps)
{
if (ps->size == 0){
fputs("Error: stack underflown", stderr);
abort();
} else
return ps->items[ --ps->size];
}
Presentation topic is stick data structure
The linked-list implementation is equally simple and straightforward. In fact, a simple singly linked list is sufficient
to implement a stack—it only requires that the head node or element can be removed, or popped, and a node can
only be inserted by becoming the new head node.
Unlike the array implementation, our structure typedef corresponds not to the entire stack structure, but to a single
node:
typedef struct stack {
int data;
struct stack *next;
} STACK;
void push(STACK **head, int value)
{
STACK *node = malloc(sizeof(STACK)); /* create a new node */
if (node == NULL){
fputs("Error: no space available for noden", stderr);
abort();
} else { /* initialize node */
node->data = value;
node->next = empty(*head) ? NULL : *head; /* insert new head if
any */
*head = node;
}
}
int pop(STACK **head)
{
if (empty(*head)) { /* stack is empty */
fputs("Error: stack underflown", stderr);
abort();
} else { //pop a node
STACK *top = *head;
int value = top->data;
*head = top->next;
free(top);
return value;
}
}
Stack (ab
Presentation topic is stick data structure

More Related Content

PPTX
Stack & Queue using Linked List in Data Structure
PPTX
2.6 transformations
DOCX
Ds
PPTX
Stack - Data Structure
PPT
Stack & queue
PPTX
Queue Implementation Using Array & Linked List
PPT
Stack and queue
PPTX
Stack operation algorithms with example
Stack & Queue using Linked List in Data Structure
2.6 transformations
Ds
Stack - Data Structure
Stack & queue
Queue Implementation Using Array & Linked List
Stack and queue
Stack operation algorithms with example

What's hot (20)

PPT
PPSX
Data Structure (Stack)
PPTX
Stack Data Structure
PDF
Data Visualization With R: Introduction
PPT
Lect 15-16 Zaheer Abbas
PPT
Stack linked list
PPTX
Stack and Queue
PPT
computer notes - Data Structures - 6
PPTX
2.5 function transformations
PDF
Data Visualization With R: Learn To Combine Multiple Graphs
PPTX
Implementation of queue using singly and doubly linked list.
PPTX
Stack project
PPTX
Project of data structure
PDF
STACK ( LIFO STRUCTURE) - Data Structure
PPT
Stacks & Queues By Ms. Niti Arora
PPTX
Group functions
PPTX
Stack of Data structure
PDF
Data Visualization With R: Learn To Modify Title, Axis Labels & Range
DOC
Async task
PPTX
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structure (Stack)
Stack Data Structure
Data Visualization With R: Introduction
Lect 15-16 Zaheer Abbas
Stack linked list
Stack and Queue
computer notes - Data Structures - 6
2.5 function transformations
Data Visualization With R: Learn To Combine Multiple Graphs
Implementation of queue using singly and doubly linked list.
Stack project
Project of data structure
STACK ( LIFO STRUCTURE) - Data Structure
Stacks & Queues By Ms. Niti Arora
Group functions
Stack of Data structure
Data Visualization With R: Learn To Modify Title, Axis Labels & Range
Async task
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Ad

Similar to Presentation topic is stick data structure (20)

PDF
04 stacks
PPSX
Stacks fundamentals
PPTX
STACK.pptx
DOCX
DSA- Unit III- STACK AND QUEUE
PDF
Chapter 5 Stack and Queue.pdf
PPTX
DATA STRUCTURE AND COMPUTER ALGORITHMS LECTURE 2
PPTX
Stacks in Data Structure
PDF
PDF
Chapter 4 stack
PPTX
The presentation on stack data structure
PDF
Data structure.pdf
DOCX
Stacks
PDF
Stack push pop
PPTX
CS8391-Data Structures Unit 2
PPTX
DS- Stack ADT
PPTX
6 - STACKS in Data Structure and Algorithm.pptx
PPT
The Stack in data structures .ppt
PPT
PPTX
Stack in Sata Structure
04 stacks
Stacks fundamentals
STACK.pptx
DSA- Unit III- STACK AND QUEUE
Chapter 5 Stack and Queue.pdf
DATA STRUCTURE AND COMPUTER ALGORITHMS LECTURE 2
Stacks in Data Structure
Chapter 4 stack
The presentation on stack data structure
Data structure.pdf
Stacks
Stack push pop
CS8391-Data Structures Unit 2
DS- Stack ADT
6 - STACKS in Data Structure and Algorithm.pptx
The Stack in data structures .ppt
Stack in Sata Structure
Ad

Recently uploaded (20)

DOCX
The story of the first moon landing.docx
PPTX
mahatma gandhi bus terminal in india Case Study.pptx
PDF
Facade & Landscape Lighting Techniques and Trends.pptx.pdf
PPTX
Wisp Textiles: Where Comfort Meets Everyday Style
PPTX
Fundamental Principles of Visual Graphic Design.pptx
PDF
Phone away, tabs closed: No multitasking
PDF
GREEN BUILDING MATERIALS FOR SUISTAINABLE ARCHITECTURE AND BUILDING STUDY
PDF
Wio LTE JP Version v1.3b- 4G, Cat.1, Espruino Compatible\202001935, PCBA;Wio ...
PDF
Quality Control Management for RMG, Level- 4, Certificate
PDF
High-frequency high-voltage transformer outline drawing
PDF
Design Thinking - Module 1 - Introduction To Design Thinking - Dr. Rohan Dasg...
PPTX
BSCS lesson 3.pptxnbbjbb mnbkjbkbbkbbkjb
PDF
BRANDBOOK-Presidential Award Scheme-Kenya-2023
PDF
SEVA- Fashion designing-Presentation.pdf
PDF
Integrated-2D-and-3D-Animation-Bridging-Dimensions-for-Impactful-Storytelling...
PDF
Interior Structure and Construction A1 NGYANQI
PPT
unit 1 ppt.ppthhhhhhhhhhhhhhhhhhhhhhhhhh
PPTX
HPE Aruba-master-icon-library_052722.pptx
PPTX
DOC-20250430-WA0014._20250714_235747_0000.pptx
PPTX
AD Bungalow Case studies Sem 2.pptxvwewev
The story of the first moon landing.docx
mahatma gandhi bus terminal in india Case Study.pptx
Facade & Landscape Lighting Techniques and Trends.pptx.pdf
Wisp Textiles: Where Comfort Meets Everyday Style
Fundamental Principles of Visual Graphic Design.pptx
Phone away, tabs closed: No multitasking
GREEN BUILDING MATERIALS FOR SUISTAINABLE ARCHITECTURE AND BUILDING STUDY
Wio LTE JP Version v1.3b- 4G, Cat.1, Espruino Compatible\202001935, PCBA;Wio ...
Quality Control Management for RMG, Level- 4, Certificate
High-frequency high-voltage transformer outline drawing
Design Thinking - Module 1 - Introduction To Design Thinking - Dr. Rohan Dasg...
BSCS lesson 3.pptxnbbjbb mnbkjbkbbkbbkjb
BRANDBOOK-Presidential Award Scheme-Kenya-2023
SEVA- Fashion designing-Presentation.pdf
Integrated-2D-and-3D-Animation-Bridging-Dimensions-for-Impactful-Storytelling...
Interior Structure and Construction A1 NGYANQI
unit 1 ppt.ppthhhhhhhhhhhhhhhhhhhhhhhhhh
HPE Aruba-master-icon-library_052722.pptx
DOC-20250430-WA0014._20250714_235747_0000.pptx
AD Bungalow Case studies Sem 2.pptxvwewev

Presentation topic is stick data structure

  • 1. PRESENTATION TOPIC IS STICK DATA STRUCTURE PRESENTED BY: AIZAZ ALI BSCS 3RD SEMESTER GPGC LANDIKOTAL PRESENTED TO: SIR MR. MUHAMMAD NISAR SAIB
  • 2. Stick definition Stick operations , pop, push, Example of stick Implementation of stack as an array and as linklist References for study and objects
  • 3. Stack definition :- A stack is a linear data structure that can be accessed only at one of its ends for storing and retrieving data. Such a stack resembles a stack of trays in a cafeteria: new trays are put on the top of the stack and taken off the top. The last tray put on stack is the first tray removed from the stack. Or A stack is a list of homogenous elements in which the addition and deletion of elements occurs only at one end, called the top of the stack. Or A data structure in which the elements are added and removed from one end
  • 5. FIGURE 1.1 An example of adding numbers 592 and 3,784 using stacks.
  • 6. Now that you know what a stack is, let us see what kinds of operations can be performed on a stack. Because new items can be added to the stack, we can perform the add operation, called push, to add an element onto the stack. Similarly, because the top item can be retrieved and/or removed from the stack, we can perform the operation top to retrieve the top element of the stack, and the operation pop to remove the top element from the stack. The push, top, and pop operations work as follows: Suppose there are boxes lying on the floor that need to be stacked on a table. Initially, all of the boxes are on the floor and the stack is empty. (See Figure 7-2.)
  • 7. First we push box A onto the stack. After the push operation, the stack is as shown in Figure 7-3(a).
  • 8. Example 2:- a series of the executed on a stack
  • 10. Array:- The array implementation aims to create an array where the first element (usually at the zero- offset) is the bottom. That is, array[0] is the first element pushed onto the stack and the last element popped off. The program must keep track of the size, or the length of the stack. The stack itself can therefore be effectively implemented as a two-element structure in C: typedef struct { size_t size; int items[STACKSIZE]; } STACK; void push(STACK *ps, int x) { if (ps->size == STACKSIZE) { fputs("Error: stack overflown", stderr); abort(); } else ps->items[ps->size++] = x; } int pop(STACK *ps) { if (ps->size == 0){ fputs("Error: stack underflown", stderr); abort(); } else return ps->items[ --ps->size]; }
  • 12. The linked-list implementation is equally simple and straightforward. In fact, a simple singly linked list is sufficient to implement a stack—it only requires that the head node or element can be removed, or popped, and a node can only be inserted by becoming the new head node. Unlike the array implementation, our structure typedef corresponds not to the entire stack structure, but to a single node: typedef struct stack { int data; struct stack *next; } STACK; void push(STACK **head, int value) { STACK *node = malloc(sizeof(STACK)); /* create a new node */ if (node == NULL){ fputs("Error: no space available for noden", stderr); abort(); } else { /* initialize node */ node->data = value; node->next = empty(*head) ? NULL : *head; /* insert new head if any */ *head = node; } }
  • 13. int pop(STACK **head) { if (empty(*head)) { /* stack is empty */ fputs("Error: stack underflown", stderr); abort(); } else { //pop a node STACK *top = *head; int value = top->data; *head = top->next; free(top); return value; } } Stack (ab