SlideShare a Scribd company logo
Data Structures
06/26/15 CS 201
Data Structure
• A construct that can be defined within a
programming language to store a
collection of data
– one may store some data in an array of
integers, an array of objects, or an array of
arrays
06/26/15 CS 201
Abstract Data Type (ADT)
• Definition: a collection of data together
with a set of operations on that data
– specifications indicate what ADT
operations do, but not how to implement
them
– data structures are part of an ADT’s
implementation
• Programmer can use an ADT without
knowing its implementation.
06/26/15 CS 201
Typical Operations on Data
• Add data to a data collection
• Remove data from a data collection
• Ask questions about the data in a data
collection. E.g., what is the value at a
particular location, and is x in the
collection?
06/26/15 CS 201
Why ADT
• Hide the unnecessary details
• Help manage software complexity
• Easier software maintenance
• Functionalities are less likely to change
• Localised rather than global changes
06/26/15 CS 201
Illustration
Stacks
06/26/15 CS 201
What is a Stack?
• A stack is a list with the restriction that
insertions and deletions can be performed in
only one position, namely, the end of the list,
called the top.
• The operations: push (insert) and pop (delete)
pop push(o)
6
7
2
3Top
06/26/15 CS 201
Stack ADT Interface
• The main functions in the Stack ADT are (S is the stack)
boolean isEmpty(); // return true if empty
boolean isFull(S); // return true if full
void push(S, item); // insert item into stack
void pop(S); // remove most recent item
void clear(S); // remove all items from stack
Item top(S); // retrieve most recent item
Item topAndPop(S); // return & remove most recent item
06/26/15 CS 201
Sample Operation
Stack S = malloc(sizeof(stack));
push(S, “a”);
push(S, “b”);
push(S, “c”);
d=top(S);
pop(S);
push(S, “e”);
pop(S);
s
abc
top
e
d
06/26/15 CS 201
Implementation by Array
• use Array with a top index pointer as an implementation of stack
E F
0 1 7 8 92 3 4 5 6
A B C D
top
StackAr
arr
A
06/26/15 CS 201
Code
06/26/15 CS 201
More code
06/26/15 CS 201
More code
Effects
06/26/15 CS 201
06/26/15 CS 201
Applications
• Many application areas use stacks:
– line editing
– bracket matching
– postfix calculation
– function call stack
Queues
06/26/15 CS 201
What is a Queue?
• Like stacks, queues are lists. With a queue,
however, insertion is done at one end whereas
deletion is done at the other end.
• Queues implement the FIFO (first-in first-out)
policy. E.g., a printer/job queue!
• Two basic operations of queues:
– dequeue: remove an item/element from front
– enqueue: add an item/element at the back
dequeue enqueue
06/26/15 CS 201
Queue ADT
• Queues implement the FIFO (first-in first-out)
policy
– An example is the printer/job queue!
enqueue(o)
dequeue()
isEmpty()
getFront() createQueue()
06/26/15 CS 201
Sample Operation
Queue *Q;
enqueue(Q, “a”);
enqueue(Q, “b”);
enqueue(Q, “c”);
d=getFront(Q);
dequeue(Q);
enqueue(Q, “e”);
dequeue(Q);
q
front back
a b c e
d
06/26/15 CS 201
Queue ADT interface
• The main functions in the Queue ADT are (Q is
the queue)
void enqueue(o, Q) // insert o to back of Q
void dequeue(Q); // remove oldest item
Item getFront(Q); // retrieve oldest item
boolean isEmpty(Q); // checks if Q is empty
boolean isFull(Q); // checks if Q is full
void clear(Q); // make Q empty
}
06/26/15 CS 201
Implementation of Queue
(Array)
• use Array with front and back pointers as implementation of
queue Queue
arr 0 1 7 8 92 3 4 5 6
A B C D E F G
front
back
06/26/15 CS 201
Circular Array
• To implement queue, it is best to view arrays as circular structure
0 1 7 8 92 3 4 5 6
A B C D E F G
front
back
front
back
A
B
C
D
EF
G
0
1
7
8
9
2
3
45
6
Circular view of arrays.
06/26/15 CS 201
How to Advance
• Both front & back pointers should make advancement until they
reach end of the array. Then, they should re-point to beginning
of the array
front = adv(front);
back = adv(back);
int adv(int p)
{ return ((p+1) % maxsize);
}
Alternatively, use modular arithmetic:
mod operator
int adv(int p)
{ int r = p+1;
if (r<maxsize) return r;
else return 0;
}
upper bound of the array
06/26/15 CS 201
Sample
Queue *Q;
enqueue(Q, “a”);
enqueue(Q, “b”);
enqueue(Q, “c”);
dequeue(Q);
dequeue(Q);
enqueue(Q, “d”);
enqueue(Q, “e”);
dequeue(Q);
a
Q
F=front
B=back
F
B
b c d
F
B B B
F F
B B
e
06/26/15 CS 201
Checking for Full/Empty State
What does (F==B) denote?
F
B
Queue
Empty
State
c de
B
F
f Queue
Full
State
size 0 size 4
c de
B F
Alternative - Leave a Deliberate Gap!
No need for size field.
Full Case : (adv(B)==F)
06/26/15 CS 201
Summary
• The definition of the queue operations
gives the ADT queue first-in, first-out
(FIFO) behavior
• The queue can be implemented by
linked lists or by arrays
• There are many applications
– Printer queues,
– Telecommunication queues,
– Simulations,
– Etc.

More Related Content

What's hot

computer notes - Data Structures - 6
computer notes - Data Structures - 6computer notes - Data Structures - 6
computer notes - Data Structures - 6ecomputernotes
 
High Fidelity Wind Model Software for Real-Time Simulation Platforms
High Fidelity Wind Model Software for Real-Time Simulation PlatformsHigh Fidelity Wind Model Software for Real-Time Simulation Platforms
High Fidelity Wind Model Software for Real-Time Simulation PlatformsSimspace Ingeniería SL
 
Using FME to Transfer Park Asset Data From an Oracle Database to Trimble GPS ...
Using FME to Transfer Park Asset Data From an Oracle Database to Trimble GPS ...Using FME to Transfer Park Asset Data From an Oracle Database to Trimble GPS ...
Using FME to Transfer Park Asset Data From an Oracle Database to Trimble GPS ...Safe Software
 
WOBC AutoDISE Brief
WOBC AutoDISE BriefWOBC AutoDISE Brief
WOBC AutoDISE Briefphase3-120A
 
Design Of 64-Bit Parallel Prefix VLSI Adder For High Speed Arithmetic Circuits
Design Of 64-Bit Parallel Prefix VLSI Adder For High Speed Arithmetic CircuitsDesign Of 64-Bit Parallel Prefix VLSI Adder For High Speed Arithmetic Circuits
Design Of 64-Bit Parallel Prefix VLSI Adder For High Speed Arithmetic CircuitsIJRES Journal
 
Auto dise paper
Auto dise paper  Auto dise paper
Auto dise paper phase3-120A
 
2. 8085 introduction to instruction
2. 8085 introduction to instruction2. 8085 introduction to instruction
2. 8085 introduction to instructionsandip das
 

What's hot (15)

Master Thesis
Master ThesisMaster Thesis
Master Thesis
 
Krishankant Sharma Portfolio
Krishankant Sharma PortfolioKrishankant Sharma Portfolio
Krishankant Sharma Portfolio
 
computer notes - Data Structures - 6
computer notes - Data Structures - 6computer notes - Data Structures - 6
computer notes - Data Structures - 6
 
High Fidelity Wind Model Software for Real-Time Simulation Platforms
High Fidelity Wind Model Software for Real-Time Simulation PlatformsHigh Fidelity Wind Model Software for Real-Time Simulation Platforms
High Fidelity Wind Model Software for Real-Time Simulation Platforms
 
Using FME to Transfer Park Asset Data From an Oracle Database to Trimble GPS ...
Using FME to Transfer Park Asset Data From an Oracle Database to Trimble GPS ...Using FME to Transfer Park Asset Data From an Oracle Database to Trimble GPS ...
Using FME to Transfer Park Asset Data From an Oracle Database to Trimble GPS ...
 
WOBC AutoDISE Brief
WOBC AutoDISE BriefWOBC AutoDISE Brief
WOBC AutoDISE Brief
 
Presentation
PresentationPresentation
Presentation
 
Design Of 64-Bit Parallel Prefix VLSI Adder For High Speed Arithmetic Circuits
Design Of 64-Bit Parallel Prefix VLSI Adder For High Speed Arithmetic CircuitsDesign Of 64-Bit Parallel Prefix VLSI Adder For High Speed Arithmetic Circuits
Design Of 64-Bit Parallel Prefix VLSI Adder For High Speed Arithmetic Circuits
 
CFG to CNF
CFG to CNFCFG to CNF
CFG to CNF
 
Auto dise paper
Auto dise paper  Auto dise paper
Auto dise paper
 
Vldb14
Vldb14Vldb14
Vldb14
 
Management Network Lec 3
Management Network Lec 3Management Network Lec 3
Management Network Lec 3
 
IMPLEMENTATION OF 128-BIT SPARSE KOGGE-STONE ADDER USING VERILOG
IMPLEMENTATION OF 128-BIT SPARSE KOGGE-STONE ADDER USING VERILOGIMPLEMENTATION OF 128-BIT SPARSE KOGGE-STONE ADDER USING VERILOG
IMPLEMENTATION OF 128-BIT SPARSE KOGGE-STONE ADDER USING VERILOG
 
Proceso desarrollo con uml
Proceso desarrollo con umlProceso desarrollo con uml
Proceso desarrollo con uml
 
2. 8085 introduction to instruction
2. 8085 introduction to instruction2. 8085 introduction to instruction
2. 8085 introduction to instruction
 

Similar to Array stack-queue1

lect- 3&4.ppt
lect- 3&4.pptlect- 3&4.ppt
lect- 3&4.pptmrizwan38
 
cs201-list-stack-queue.ppt
cs201-list-stack-queue.pptcs201-list-stack-queue.ppt
cs201-list-stack-queue.pptRahulYadav738822
 
Queue implementation
Queue implementationQueue implementation
Queue implementationRajendran
 
Data Structures - Lecture 2 - Unit 2.pptx
Data Structures - Lecture 2 - Unit 2.pptxData Structures - Lecture 2 - Unit 2.pptx
Data Structures - Lecture 2 - Unit 2.pptxDanielNesaKumarC
 
C++ Program It is only 1 rotation. Up-rotation of a stack. Write a.pdf
C++ Program It is only 1 rotation. Up-rotation of a stack.  Write a.pdfC++ Program It is only 1 rotation. Up-rotation of a stack.  Write a.pdf
C++ Program It is only 1 rotation. Up-rotation of a stack. Write a.pdfpallavi953613
 
Hands-On with U-SQL and Azure Data Lake Analytics (ADLA)
Hands-On with U-SQL and Azure Data Lake Analytics (ADLA)Hands-On with U-SQL and Azure Data Lake Analytics (ADLA)
Hands-On with U-SQL and Azure Data Lake Analytics (ADLA)Jason L Brugger
 
Stack Data Structure with Static Implementation (2).pptx
Stack Data Structure with Static Implementation (2).pptxStack Data Structure with Static Implementation (2).pptx
Stack Data Structure with Static Implementation (2).pptxEmroz Sardar
 
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbbqueuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbbRAtna29
 
13 Stacks and Queues.pptx
13 Stacks and Queues.pptx13 Stacks and Queues.pptx
13 Stacks and Queues.pptxssuserb7c8b8
 
Complete the implementation of the Weighted Graph that we began in t.pdf
Complete the implementation of the Weighted Graph that we began in t.pdfComplete the implementation of the Weighted Graph that we began in t.pdf
Complete the implementation of the Weighted Graph that we began in t.pdfmarketing413921
 
lecture10trsgfchjvxgfzfdchgdchgcgshyjh.ppt
lecture10trsgfchjvxgfzfdchgdchgcgshyjh.pptlecture10trsgfchjvxgfzfdchgdchgcgshyjh.ppt
lecture10trsgfchjvxgfzfdchgdchgcgshyjh.pptpartho5958
 

Similar to Array stack-queue1 (20)

lect- 3&4.ppt
lect- 3&4.pptlect- 3&4.ppt
lect- 3&4.ppt
 
cs201-list-stack-queue.ppt
cs201-list-stack-queue.pptcs201-list-stack-queue.ppt
cs201-list-stack-queue.ppt
 
Queue implementation
Queue implementationQueue implementation
Queue implementation
 
Data Structures - Lecture 2 - Unit 2.pptx
Data Structures - Lecture 2 - Unit 2.pptxData Structures - Lecture 2 - Unit 2.pptx
Data Structures - Lecture 2 - Unit 2.pptx
 
Lecture 07
Lecture 07Lecture 07
Lecture 07
 
C++ Program It is only 1 rotation. Up-rotation of a stack. Write a.pdf
C++ Program It is only 1 rotation. Up-rotation of a stack.  Write a.pdfC++ Program It is only 1 rotation. Up-rotation of a stack.  Write a.pdf
C++ Program It is only 1 rotation. Up-rotation of a stack. Write a.pdf
 
Hands-On with U-SQL and Azure Data Lake Analytics (ADLA)
Hands-On with U-SQL and Azure Data Lake Analytics (ADLA)Hands-On with U-SQL and Azure Data Lake Analytics (ADLA)
Hands-On with U-SQL and Azure Data Lake Analytics (ADLA)
 
2 a stacks
2 a stacks2 a stacks
2 a stacks
 
Unit 5 dsa QUEUE
Unit 5 dsa QUEUEUnit 5 dsa QUEUE
Unit 5 dsa QUEUE
 
Cp unit 3
Cp unit 3Cp unit 3
Cp unit 3
 
Stack Data Structure with Static Implementation (2).pptx
Stack Data Structure with Static Implementation (2).pptxStack Data Structure with Static Implementation (2).pptx
Stack Data Structure with Static Implementation (2).pptx
 
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbbqueuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
 
Stack in C.pptx
Stack in C.pptxStack in C.pptx
Stack in C.pptx
 
13 Stacks and Queues.pptx
13 Stacks and Queues.pptx13 Stacks and Queues.pptx
13 Stacks and Queues.pptx
 
L7 pointers
L7 pointersL7 pointers
L7 pointers
 
Complete the implementation of the Weighted Graph that we began in t.pdf
Complete the implementation of the Weighted Graph that we began in t.pdfComplete the implementation of the Weighted Graph that we began in t.pdf
Complete the implementation of the Weighted Graph that we began in t.pdf
 
Stack in Sata Structure
Stack in Sata StructureStack in Sata Structure
Stack in Sata Structure
 
Ch06 Stack
Ch06  StackCh06  Stack
Ch06 Stack
 
lecture10trsgfchjvxgfzfdchgdchgcgshyjh.ppt
lecture10trsgfchjvxgfzfdchgdchgcgshyjh.pptlecture10trsgfchjvxgfzfdchgdchgcgshyjh.ppt
lecture10trsgfchjvxgfzfdchgdchgcgshyjh.ppt
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
 

More from Rajendran

Element distinctness lower bounds
Element distinctness lower boundsElement distinctness lower bounds
Element distinctness lower boundsRajendran
 
Scheduling with Startup and Holding Costs
Scheduling with Startup and Holding CostsScheduling with Startup and Holding Costs
Scheduling with Startup and Holding CostsRajendran
 
Divide and conquer surfing lower bounds
Divide and conquer  surfing lower boundsDivide and conquer  surfing lower bounds
Divide and conquer surfing lower boundsRajendran
 
Red black tree
Red black treeRed black tree
Red black treeRajendran
 
Medians and order statistics
Medians and order statisticsMedians and order statistics
Medians and order statisticsRajendran
 
Proof master theorem
Proof master theoremProof master theorem
Proof master theoremRajendran
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree methodRajendran
 
Recurrence theorem
Recurrence theoremRecurrence theorem
Recurrence theoremRajendran
 
Master method
Master method Master method
Master method Rajendran
 
Master method theorem
Master method theoremMaster method theorem
Master method theoremRajendran
 
Master method theorem
Master method theoremMaster method theorem
Master method theoremRajendran
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithmsRajendran
 
Longest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm AnalysisLongest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm AnalysisRajendran
 
Dynamic programming in Algorithm Analysis
Dynamic programming in Algorithm AnalysisDynamic programming in Algorithm Analysis
Dynamic programming in Algorithm AnalysisRajendran
 
Average case Analysis of Quicksort
Average case Analysis of QuicksortAverage case Analysis of Quicksort
Average case Analysis of QuicksortRajendran
 
Np completeness
Np completenessNp completeness
Np completenessRajendran
 
computer languages
computer languagescomputer languages
computer languagesRajendran
 

More from 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
 

Recently uploaded

Benefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational ResourcesBenefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational Resourcesdimpy50
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...Nguyen Thanh Tu Collection
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasiemaillard
 
Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportAvinash Rai
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345beazzy04
 
Salient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxSalient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxakshayaramakrishnan21
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativePeter Windle
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxJisc
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdfCarlosHernanMontoyab2
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxbennyroshan06
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...Sayali Powar
 
NLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptxNLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptxssuserbdd3e8
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptxJosvitaDsouza2
 
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...Denish Jangid
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfbu07226
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfjoachimlavalley1
 
plant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated cropsplant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated cropsparmarsneha2
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...Nguyen Thanh Tu Collection
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxRaedMohamed3
 

Recently uploaded (20)

Benefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational ResourcesBenefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational Resources
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training Report
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Salient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxSalient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptx
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
 
NLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptxNLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
plant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated cropsplant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated crops
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 

Array stack-queue1

  • 2. 06/26/15 CS 201 Data Structure • A construct that can be defined within a programming language to store a collection of data – one may store some data in an array of integers, an array of objects, or an array of arrays
  • 3. 06/26/15 CS 201 Abstract Data Type (ADT) • Definition: a collection of data together with a set of operations on that data – specifications indicate what ADT operations do, but not how to implement them – data structures are part of an ADT’s implementation • Programmer can use an ADT without knowing its implementation.
  • 4. 06/26/15 CS 201 Typical Operations on Data • Add data to a data collection • Remove data from a data collection • Ask questions about the data in a data collection. E.g., what is the value at a particular location, and is x in the collection?
  • 5. 06/26/15 CS 201 Why ADT • Hide the unnecessary details • Help manage software complexity • Easier software maintenance • Functionalities are less likely to change • Localised rather than global changes
  • 8. 06/26/15 CS 201 What is a Stack? • A stack is a list with the restriction that insertions and deletions can be performed in only one position, namely, the end of the list, called the top. • The operations: push (insert) and pop (delete) pop push(o) 6 7 2 3Top
  • 9. 06/26/15 CS 201 Stack ADT Interface • The main functions in the Stack ADT are (S is the stack) boolean isEmpty(); // return true if empty boolean isFull(S); // return true if full void push(S, item); // insert item into stack void pop(S); // remove most recent item void clear(S); // remove all items from stack Item top(S); // retrieve most recent item Item topAndPop(S); // return & remove most recent item
  • 10. 06/26/15 CS 201 Sample Operation Stack S = malloc(sizeof(stack)); push(S, “a”); push(S, “b”); push(S, “c”); d=top(S); pop(S); push(S, “e”); pop(S); s abc top e d
  • 11. 06/26/15 CS 201 Implementation by Array • use Array with a top index pointer as an implementation of stack E F 0 1 7 8 92 3 4 5 6 A B C D top StackAr arr A
  • 16. 06/26/15 CS 201 Applications • Many application areas use stacks: – line editing – bracket matching – postfix calculation – function call stack
  • 18. 06/26/15 CS 201 What is a Queue? • Like stacks, queues are lists. With a queue, however, insertion is done at one end whereas deletion is done at the other end. • Queues implement the FIFO (first-in first-out) policy. E.g., a printer/job queue! • Two basic operations of queues: – dequeue: remove an item/element from front – enqueue: add an item/element at the back dequeue enqueue
  • 19. 06/26/15 CS 201 Queue ADT • Queues implement the FIFO (first-in first-out) policy – An example is the printer/job queue! enqueue(o) dequeue() isEmpty() getFront() createQueue()
  • 20. 06/26/15 CS 201 Sample Operation Queue *Q; enqueue(Q, “a”); enqueue(Q, “b”); enqueue(Q, “c”); d=getFront(Q); dequeue(Q); enqueue(Q, “e”); dequeue(Q); q front back a b c e d
  • 21. 06/26/15 CS 201 Queue ADT interface • The main functions in the Queue ADT are (Q is the queue) void enqueue(o, Q) // insert o to back of Q void dequeue(Q); // remove oldest item Item getFront(Q); // retrieve oldest item boolean isEmpty(Q); // checks if Q is empty boolean isFull(Q); // checks if Q is full void clear(Q); // make Q empty }
  • 22. 06/26/15 CS 201 Implementation of Queue (Array) • use Array with front and back pointers as implementation of queue Queue arr 0 1 7 8 92 3 4 5 6 A B C D E F G front back
  • 23. 06/26/15 CS 201 Circular Array • To implement queue, it is best to view arrays as circular structure 0 1 7 8 92 3 4 5 6 A B C D E F G front back front back A B C D EF G 0 1 7 8 9 2 3 45 6 Circular view of arrays.
  • 24. 06/26/15 CS 201 How to Advance • Both front & back pointers should make advancement until they reach end of the array. Then, they should re-point to beginning of the array front = adv(front); back = adv(back); int adv(int p) { return ((p+1) % maxsize); } Alternatively, use modular arithmetic: mod operator int adv(int p) { int r = p+1; if (r<maxsize) return r; else return 0; } upper bound of the array
  • 25. 06/26/15 CS 201 Sample Queue *Q; enqueue(Q, “a”); enqueue(Q, “b”); enqueue(Q, “c”); dequeue(Q); dequeue(Q); enqueue(Q, “d”); enqueue(Q, “e”); dequeue(Q); a Q F=front B=back F B b c d F B B B F F B B e
  • 26. 06/26/15 CS 201 Checking for Full/Empty State What does (F==B) denote? F B Queue Empty State c de B F f Queue Full State size 0 size 4 c de B F Alternative - Leave a Deliberate Gap! No need for size field. Full Case : (adv(B)==F)
  • 27. 06/26/15 CS 201 Summary • The definition of the queue operations gives the ADT queue first-in, first-out (FIFO) behavior • The queue can be implemented by linked lists or by arrays • There are many applications – Printer queues, – Telecommunication queues, – Simulations, – Etc.