SlideShare ist ein Scribd-Unternehmen logo
1 von 7
Implementation of stack using
Array
Struct StackRecord
{
int Capacity;
int TopOfStack;
ElementType *Array;
}
#define STACKSIZE 100
Struct StackRecord
{ int top;
ElementType
Array[STACKSIZE];
}
Implementation of stack using
Array
• Test for empty stack
empty (stack *ps)
{
return (ps → top == -1)
}
Implementation using Array
• Pop top element from stack
int pop (stack *ps)
{ int x
if (empty (ps))
printf (“%sn”, “stack underflow!”);
else
{ x = ps → array [ps → top];
(ps → top)--;
return (x); }
}
Implementation using Array
• Push an element onto the stack
push (stack *ps, int x)
{ if (ps → top == STACKSIZE – 1)
printf (“%sn”, “stack overflow!”);
else
{ (ps → top)++;
ps → items [ps → top] = x;
}
}
Variable types of stack elements
#define STACKSIZE 100
#define INTGR 1
#define FLT 2
#define STRING 3
struct stackelement
{
int etype; /* element type */
union
{ int ival;
float fval;
char *pval;
} element; /* end union */
}
Variable Types of Stack Elements
• To access the top element
struct stack s;
struct stackelement se;
se = s.items [s.top];
switch (se.etype)
{
case INTGR: printf (“%dn”, se.ival); break;
case FLT: printf (“%dn”, se.fval); break;
case STRING: printf (“%sn”, se.pval);
}
Variable Types of Stack Elements
• To access the top element
struct stack s;
struct stackelement se;
se = s.items [s.top];
switch (se.etype)
{
case INTGR: printf (“%dn”, se.ival); break;
case FLT: printf (“%dn”, se.fval); break;
case STRING: printf (“%sn”, se.pval);
}

Weitere ähnliche Inhalte

Was ist angesagt?

2 3. standard io
2 3. standard io2 3. standard io
2 3. standard io
웅식 전
 

Was ist angesagt? (20)

Avl tree
Avl treeAvl tree
Avl tree
 
week-16x
week-16xweek-16x
week-16x
 
DS- Stack ADT
DS- Stack ADTDS- Stack ADT
DS- Stack ADT
 
Final ds record
Final ds recordFinal ds record
Final ds record
 
week-1x
week-1xweek-1x
week-1x
 
week-18x
week-18xweek-18x
week-18x
 
week-10x
week-10xweek-10x
week-10x
 
Qprgs
QprgsQprgs
Qprgs
 
week-17x
week-17xweek-17x
week-17x
 
week-6x
week-6xweek-6x
week-6x
 
2 3. standard io
2 3. standard io2 3. standard io
2 3. standard io
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
Single linked list
Single linked listSingle linked list
Single linked list
 
01 list using array
01 list using array01 list using array
01 list using array
 
Stack concepts by Divya
Stack concepts by DivyaStack concepts by Divya
Stack concepts by Divya
 
Recursion concepts by Divya
Recursion concepts by DivyaRecursion concepts by Divya
Recursion concepts by Divya
 
Double linked list
Double linked listDouble linked list
Double linked list
 
Bcsl 033 data and file structures lab s5-3
Bcsl 033 data and file structures lab s5-3Bcsl 033 data and file structures lab s5-3
Bcsl 033 data and file structures lab s5-3
 
Bcsl 033 data and file structures lab s3-3
Bcsl 033 data and file structures lab s3-3Bcsl 033 data and file structures lab s3-3
Bcsl 033 data and file structures lab s3-3
 

Ähnlich wie StackArray stack3

please tell me what lines do i alter to make this stack a queue. tel.pdf
please tell me what lines do i alter to make this stack a queue. tel.pdfplease tell me what lines do i alter to make this stack a queue. tel.pdf
please tell me what lines do i alter to make this stack a queue. tel.pdf
agarshailenterprises
 
Implement the ADT stack by using an array stack to contain its entri.pdf
Implement the ADT stack by using an array stack to contain its entri.pdfImplement the ADT stack by using an array stack to contain its entri.pdf
Implement the ADT stack by using an array stack to contain its entri.pdf
SIGMATAX1
 
03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays
tameemyousaf
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
sreekanth3dce
 
Stack linked list
Stack linked listStack linked list
Stack linked list
bhargav0077
 

Ähnlich wie StackArray stack3 (20)

Stacks
StacksStacks
Stacks
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Project of data structure
Project of data structureProject of data structure
Project of data structure
 
please tell me what lines do i alter to make this stack a queue. tel.pdf
please tell me what lines do i alter to make this stack a queue. tel.pdfplease tell me what lines do i alter to make this stack a queue. tel.pdf
please tell me what lines do i alter to make this stack a queue. tel.pdf
 
Implement the ADT stack by using an array stack to contain its entri.pdf
Implement the ADT stack by using an array stack to contain its entri.pdfImplement the ADT stack by using an array stack to contain its entri.pdf
Implement the ADT stack by using an array stack to contain its entri.pdf
 
Data Structure.pptx
Data Structure.pptxData Structure.pptx
Data Structure.pptx
 
stack (1).pptx
stack (1).pptxstack (1).pptx
stack (1).pptx
 
Stack
StackStack
Stack
 
Please review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdfPlease review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdf
 
03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays
 
Unit 3 stack
Unit   3 stackUnit   3 stack
Unit 3 stack
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
 
Stack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationStack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparation
 
Data Structure Lecture 2
Data Structure Lecture 2Data Structure Lecture 2
Data Structure Lecture 2
 
Stack linked list
Stack linked listStack linked list
Stack linked list
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
Data structure output 1
Data structure output 1Data structure output 1
Data structure output 1
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
 
STACK.pptx
STACK.pptxSTACK.pptx
STACK.pptx
 
#includeiostream#includecctypeusing namespace std;cl.docx
#includeiostream#includecctypeusing namespace std;cl.docx#includeiostream#includecctypeusing namespace std;cl.docx
#includeiostream#includecctypeusing namespace std;cl.docx
 

Mehr von Rajendran

Mehr von Rajendran (20)

Element distinctness lower bounds
Element distinctness lower boundsElement distinctness lower bounds
Element distinctness lower bounds
 
Scheduling with Startup and Holding Costs
Scheduling with Startup and Holding CostsScheduling with Startup and Holding Costs
Scheduling with Startup and Holding Costs
 
Divide and conquer surfing lower bounds
Divide and conquer  surfing lower boundsDivide and conquer  surfing lower bounds
Divide and conquer surfing lower bounds
 
Red black tree
Red black treeRed black tree
Red black tree
 
Hash table
Hash tableHash table
Hash table
 
Medians and order statistics
Medians and order statisticsMedians and order statistics
Medians and order statistics
 
Proof master theorem
Proof master theoremProof master theorem
Proof master theorem
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
 
Recurrence theorem
Recurrence theoremRecurrence theorem
Recurrence theorem
 
Master method
Master method Master method
Master method
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
 
Hash tables
Hash tablesHash tables
Hash tables
 
Lower bound
Lower boundLower bound
Lower bound
 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
Longest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm AnalysisLongest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm Analysis
 
Dynamic programming in Algorithm Analysis
Dynamic programming in Algorithm AnalysisDynamic programming in Algorithm Analysis
Dynamic programming in Algorithm Analysis
 
Average case Analysis of Quicksort
Average case Analysis of QuicksortAverage case Analysis of Quicksort
Average case Analysis of Quicksort
 
Np completeness
Np completenessNp completeness
Np completeness
 
computer languages
computer languagescomputer languages
computer languages
 

Kürzlich hochgeladen

Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Krashi Coaching
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Kürzlich hochgeladen (20)

General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 

StackArray stack3

  • 1. Implementation of stack using Array Struct StackRecord { int Capacity; int TopOfStack; ElementType *Array; } #define STACKSIZE 100 Struct StackRecord { int top; ElementType Array[STACKSIZE]; }
  • 2. Implementation of stack using Array • Test for empty stack empty (stack *ps) { return (ps → top == -1) }
  • 3. Implementation using Array • Pop top element from stack int pop (stack *ps) { int x if (empty (ps)) printf (“%sn”, “stack underflow!”); else { x = ps → array [ps → top]; (ps → top)--; return (x); } }
  • 4. Implementation using Array • Push an element onto the stack push (stack *ps, int x) { if (ps → top == STACKSIZE – 1) printf (“%sn”, “stack overflow!”); else { (ps → top)++; ps → items [ps → top] = x; } }
  • 5. Variable types of stack elements #define STACKSIZE 100 #define INTGR 1 #define FLT 2 #define STRING 3 struct stackelement { int etype; /* element type */ union { int ival; float fval; char *pval; } element; /* end union */ }
  • 6. Variable Types of Stack Elements • To access the top element struct stack s; struct stackelement se; se = s.items [s.top]; switch (se.etype) { case INTGR: printf (“%dn”, se.ival); break; case FLT: printf (“%dn”, se.fval); break; case STRING: printf (“%sn”, se.pval); }
  • 7. Variable Types of Stack Elements • To access the top element struct stack s; struct stackelement se; se = s.items [s.top]; switch (se.etype) { case INTGR: printf (“%dn”, se.ival); break; case FLT: printf (“%dn”, se.fval); break; case STRING: printf (“%sn”, se.pval); }