SlideShare a Scribd company logo
KPD8013
PROGRAMMING III
INTRODUCTION to course
• Credit Hour: 3.0
• Contact Hour: 5 hours
Tuesday (8.00 – 1.30 pm)
1.0 Data Structures
1.1 Introduction to Data
Structures
1.1.1 Define Data Structures
• A data structure is a scheme for
organizing data in the memory of a
computer.
• A way of storing and organizing data
in a computer so that it can be used
efficiently
1.1.1 Define Data Structures
• Some of the more commonly used
data structures include lists, arrays,
stacks, queues, heaps, trees, and
graphs.
• The way in which the data is organized
affects the performance of a program
for different tasks.
1.1.1 Define Data Structures
• Computer programmers decide which
data structures to use based on the
nature of the data and the processes
that need to be performed on that
data.
Array
Linked List
Tree
Queue Stack
1.1.1 Define Data Structures
Types of data structures
1.1.1 Define Data Structures
The Need for Data Structures
• Goal: to organize data
• Criteria: to facilitate efficient
 storage of data
 retrieval of data
 manipulation of data
1.1.1 Define Data Structures
The Need for Data Structures
• Design Issue:
 select and design appropriate data types
(This is the main motivation to learn and underst
and data structures)
1.1.1 Define Data Structures
Data Structure Operations
• Traversing
 Accessing each data element exactly once so that certain items in
the data may be processed
• Searching
 Finding the location of the data element (key) in the structure
• Insertion
 Adding a new data element to the structure
1.1.1 Define Data Structures
Data Structure Operations
• Deletion
 Removing a data element from the structure
• Sorting
 Arrange the data elements in a logical order (ascending/
descending)
• Merging
 Combining data elements from two or more data structures into
one
1.1.2 Apply Stacks, Queues, Linked Lists
in programming
Stack
• Based on the principle of Last In First
Out (LIFO)
• Used extensively at every level of a
modern computer system (compiler etc.)
1.1.2 Apply Stacks, Queues, Linked Lists
in programming
Stack
• It is named stack as it behaves like a
real-world stack. For example – a stack
of books or a pile of plates, etc.
1.1.2 Apply Stacks, Queues, Linked Lists
in programming
Stack Representation
• The following diagram depicts a stack
and its operations.
1.1.2 Apply Stacks, Queues, Linked Lists
in programming
Stack Operations
• Peek: If the stack is not empty, return its
top element.
• Pop: If the stack is not empty, delete
and return its top element.
1.1.2 Apply Stacks, Queues, Linked Lists
in programming
Stack Operations
• Push: Add a given element to the top of
the stack.
• Size: Return the number of elements in
the stack.
1.1.2 Apply Stacks, Queues, Linked Lists
in programming
UML Diagram
Translate into a Java interface Stack.java
<<interface>>
Stack
+peek(): Object
+pop(): Object
+push(Object)
+size(): int
1.1.2 Apply Stacks, Queues, Linked Lists
in programming
Stack Example:
…
Stack crates = new ArrayStack(4);
crates.push(“CARROT”);
crates.push(“ORANGES”);
crates.push(“RAISIN”);
crates.pop();
crates.pop();
crates.push(“PEACH”);
crates.push(“BANANAS”);
crates.pop();
1.1.2 Apply Stacks, Queues, Linked Lists
in programming
Stack Example:
CARROT ORANGE
CARROT ORANGE
CARROT
RAISIN ORANGE
CARROT
CARROT PEACH
CARROT PEACH
CARROT
BANANAS
1.1.2 Apply Stacks, Queues, Linked Lists
in programming
Stack Exercise:
Stack stack= new ArrayStack();
stack.push(“Monday”);
stack.push(“Tuesday”);
stack.push(“Wednesday”);
stack.pop();
stack.pop();
stack.push(“Thursday”);
stack.push(“Friday”);
stack.pop();
stack.push(“Saturday”);
stack.push(“Sunday”);
stack.pop();
stack.pop();
1.1.2 Apply Stacks, Queues, Linked Lists
in programming
Stack Answer:
Thursday
Monday
1.1.2 Apply Stacks, Queues, Linked Lists
in programming
An Array Implementation
• Several way to implement stack
interface.
• Simplest way is to use an ordinary
array.
1.1.2 Apply Stacks, Queues, Linked Lists
in programming
An Array Implementation
<<interface>>
Stack
+peek() :Object
+pop() :Object
+push(Object)
+size() :int
ArrayStack
-a :Object[]
-size :int
+ArrayStack(int)
+isEmpty():boolean
+peek() :Object
+pop() :Object
+push(Object)
+size() :int
-resize()
1.1.2 Apply Stacks, Queues, Linked Lists
in programming
An Array Implementation
Stack.java
ArrayStack.java
TestArrayStack.java
1.1.2 Apply Stacks, Queues, Linked Lists
in programming
An Array Implementation (refer to
ArrayStack.java)
• ArrayStack implementation uses a backing
array a[] to store the stack’s elements.
• Its other field is the integer size, which
keeps a count of the number of elements
in the stack.
1.1.2 Apply Stacks, Queues, Linked Lists
in programming
An Array Implementation (refer to
ArrayStack.java)
• In addition to the four methods
required by the interface, the class also
includes a public isEmpty() method and
a private resize() method.
1.1.2 Apply Stacks, Queues, Linked Lists
in programming
An Array Implementation (refer to
ArrayStack.java)
• The latter is called by push() when the
array is full.
• Its rebuild the array, doubling its size.
• This is done by declaring a temporary reference
aa[] to the array in line 35.
1.1.2 Apply Stacks, Queues, Linked Lists
in programming
An Array Implementation (refer to
ArrayStack.java)
• Redefining a[] as a new array with twice
the length in line 36.
• Using the arraycopy() method of the
system class to copy all the stack elements
from aa[] back to a[] in line 37.
1.1.2 Apply Stacks, Queues, Linked Lists
in programming
An Array Implementation (refer to
ArrayStack.java)
• The peek() and pop() methods required
that the stack be not empty.
• This constrain enforce at line 14 and 19.
1.1.2 Apply Stacks, Queues, Linked Lists
in programming
An Array Implementation (refer to
ArrayStack.java)
• Note at line 21 the pop() method resets
to null the array element that references
the object being remove from the stack.
1.1.2 Apply Stacks, Queues, Linked Lists
in programming
An Array Implementation (refer to
ArrayStack.java)
• This prevents an unreachable reference
from being maintain.
• This class is tested in TestArrayStack.java
1.1.2 Apply Stacks, Queues, Linked Lists
in programming
Queue
• is a data structure that implements the
first-in-first-out (FIFO) protocol.
• The only access point in the structure are
at its ends where the elements are
inserted and removed.
1.1.2 Apply Stacks, Queues, Linked Lists
in programming
Queue
• Insertions are always made at the back
of the queue.
• Removals are always made at the front.
1.1.2 Apply Stacks, Queues, Linked Lists
in programming
Queue
• The queue data structure abstracts the
notion of an ordinary waiting line such
as a line of people waiting to purchase
admission tickets.
1.1.2 Apply Stacks, Queues, Linked Lists
in programming
Queue Operations
• Add: Insert a given element at the back of
the queue.
• First: If the queue is not empty, return the
element that is at the front of the queue.
1.1.2 Apply Stacks, Queues, Linked Lists
in programming
Queue Operations
• Remove: If the queue is not empty, delete
and return the element that is at the front
of the queue.
• Size: Return the number of elements in the
queue.
1.1.2 Apply Stacks, Queues, Linked Lists
in programming
Queue Operations
Translate into a Java interface Queue.java
<<interface>>
Queue
+add(object)
+first(): object
+remove(): object
+size(): int
1.1.2 Apply Stacks, Queues, Linked Lists
in programming
Queue Example:
…
Queue queue = new
ArrayQueue();
queue.add(“CARROT”);
queue.add(“ORANGES”);
queue.add(“RAISIN”);
queue.remove();
queue.remove();
queue.add(“PEACH”);
queue.add(“BANANAS”);
queue.remove();
queue.add(“DURIAN”);
queue.add(“GRAPES”);
queue.remove();
queue.remove();
1.1.2 Apply Stacks, Queues, Linked Lists
in programming
Stack Example:
CARROT ORANGECARROT RAISINORANGECARROT
RAISINORANGE RAISIN PEACHRAISIN
BANANASPEACHRAISIN BANANASPEACH
DURIANBANANASPEACH
DURIANBANANASPEACH GRAPES
1.1.2 Apply Stacks, Queues, Linked Lists
in programming
Stack Example:
DURIANBANANAS GRAPES
DURIAN GRAPES
1.1.2 Apply Stacks, Queues, Linked Lists
in programming
Queue Exercise:
…
Queue queue = new
ArrayQueue();
queue.add(“MONDAY”);
queue.add(“TUESDAY”);
queue.add(“SUNDAY”);
queue.remove();
queue.remove();
queue.add(“WEDNESDAY”);
queue.add(“SATURDAY”);
queue.remove();
queue.remove();
queue.add(“THURSDAY”);
queue.add(“FRIDAY”);
queue.remove();
queue.remove();
1.1.2 Apply Stacks, Queues, Linked Lists
in programming
Queue Answer:
Friday
1.1.2 Apply Stacks, Queues, Linked Lists
in programming
An Queue Implementation
• Several way to implement queue
interface.
• Simplest way is to use an array as we did
with the ArrayStack implementation of the
Stack interface.
1.1.2 Apply Stacks, Queues, Linked Lists
in programming
An Queue Implementation
• The simplest alternative way to an array
implementation is a linked
implementation.

More Related Content

PPTX
Ist year Msc,2nd sem module1
PPTX
Step By Step Guide to Learn R
PPT
Data structure
PPTX
Data Structure and Algorithms
PDF
Data structures Basics
PDF
Week 2 - Data Structures and Algorithms
PDF
Data structures and algorithm analysis in java
PPTX
264finalppt (1)
Ist year Msc,2nd sem module1
Step By Step Guide to Learn R
Data structure
Data Structure and Algorithms
Data structures Basics
Week 2 - Data Structures and Algorithms
Data structures and algorithm analysis in java
264finalppt (1)

What's hot (20)

PPT
Data Structures
PPTX
R- Introduction
PPT
Queue Data Structure
PPTX
Unit 2 linear data structures
PPT
Data structure lecture 1
PDF
Elementary data structure
PPTX
Introduction to data structure and algorithms
PDF
R training3
PPTX
Wrokflow programming and provenance query model
PPTX
Lecture 01 Intro to DSA
PDF
PPT
Abstract data types
PDF
Lecture 01 variables scripts and operations
PDF
DATA STRUCTURES USING C -ENGGDIGEST
PPTX
Lecture 1 and 2
PPT
Introduction of data structure
PDF
Neural Networks made easy
PPTX
Data structure and algorithm All in One
PDF
Data structures (introduction)
PPT
Data Structures 7
Data Structures
R- Introduction
Queue Data Structure
Unit 2 linear data structures
Data structure lecture 1
Elementary data structure
Introduction to data structure and algorithms
R training3
Wrokflow programming and provenance query model
Lecture 01 Intro to DSA
Abstract data types
Lecture 01 variables scripts and operations
DATA STRUCTURES USING C -ENGGDIGEST
Lecture 1 and 2
Introduction of data structure
Neural Networks made easy
Data structure and algorithm All in One
Data structures (introduction)
Data Structures 7
Ad

Similar to Introduction data structure (20)

PPTX
STACK.pptx
PPTX
stack.pptx
PPTX
b,Sc it data structure.pptx
PPT
b,Sc it data structure.ppt
PPTX
b,Sc it data structure.pptx
PPTX
Data Structure & Algorithm.pptx
PPTX
QUEUE in data-structure (classification, working procedure, Applications)
PPTX
Data Structures - Lecture 1 - Unit 1.pptx
PPT
data structures queue stack insert and delete time complexity
PPTX
Data Structures and Algorithms: introduction
PPTX
Queue collection of Frame work in oops through java
PPTX
Standard Template Library
PPT
1. Data structures introduction
PPTX
Data structure and algorithm using java
PDF
Unit 1 OF DS FOR AI DS BTRCH OF DS FOR AI DS BTRCH .pdf
PPTX
II B.Sc IT DATA STRUCTURES.pptx
PPTX
stacks and queues for public
PPTX
UNIT 1.pptx
PPTX
Introduction to DS.pptx
STACK.pptx
stack.pptx
b,Sc it data structure.pptx
b,Sc it data structure.ppt
b,Sc it data structure.pptx
Data Structure & Algorithm.pptx
QUEUE in data-structure (classification, working procedure, Applications)
Data Structures - Lecture 1 - Unit 1.pptx
data structures queue stack insert and delete time complexity
Data Structures and Algorithms: introduction
Queue collection of Frame work in oops through java
Standard Template Library
1. Data structures introduction
Data structure and algorithm using java
Unit 1 OF DS FOR AI DS BTRCH OF DS FOR AI DS BTRCH .pdf
II B.Sc IT DATA STRUCTURES.pptx
stacks and queues for public
UNIT 1.pptx
Introduction to DS.pptx
Ad

More from MUHAMMAD ISMAIL (10)

PPTX
Elemen multimedia
PPTX
Medium penghantaran
PPTX
Konsep multimedia
PPTX
Topik Multimedia 4.2
PPTX
Keperluan perisian
PPTX
Medium penghantaran
PPTX
Pemasangan nic
PPTX
Keperluan perkakasan
PPTX
Topologi rangkaian
PPTX
Langkah-Langkah Pemasangan Kabel
Elemen multimedia
Medium penghantaran
Konsep multimedia
Topik Multimedia 4.2
Keperluan perisian
Medium penghantaran
Pemasangan nic
Keperluan perkakasan
Topologi rangkaian
Langkah-Langkah Pemasangan Kabel

Recently uploaded (20)

PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
Lesson notes of climatology university.
PPTX
Pharma ospi slides which help in ospi learning
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Anesthesia in Laparoscopic Surgery in India
Abdominal Access Techniques with Prof. Dr. R K Mishra
102 student loan defaulters named and shamed – Is someone you know on the list?
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
TR - Agricultural Crops Production NC III.pdf
Lesson notes of climatology university.
Pharma ospi slides which help in ospi learning
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Microbial disease of the cardiovascular and lymphatic systems
VCE English Exam - Section C Student Revision Booklet
O5-L3 Freight Transport Ops (International) V1.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
O7-L3 Supply Chain Operations - ICLT Program
STATICS OF THE RIGID BODIES Hibbelers.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf

Introduction data structure

  • 2. INTRODUCTION to course • Credit Hour: 3.0 • Contact Hour: 5 hours Tuesday (8.00 – 1.30 pm)
  • 3. 1.0 Data Structures 1.1 Introduction to Data Structures
  • 4. 1.1.1 Define Data Structures • A data structure is a scheme for organizing data in the memory of a computer. • A way of storing and organizing data in a computer so that it can be used efficiently
  • 5. 1.1.1 Define Data Structures • Some of the more commonly used data structures include lists, arrays, stacks, queues, heaps, trees, and graphs. • The way in which the data is organized affects the performance of a program for different tasks.
  • 6. 1.1.1 Define Data Structures • Computer programmers decide which data structures to use based on the nature of the data and the processes that need to be performed on that data.
  • 7. Array Linked List Tree Queue Stack 1.1.1 Define Data Structures Types of data structures
  • 8. 1.1.1 Define Data Structures The Need for Data Structures • Goal: to organize data • Criteria: to facilitate efficient  storage of data  retrieval of data  manipulation of data
  • 9. 1.1.1 Define Data Structures The Need for Data Structures • Design Issue:  select and design appropriate data types (This is the main motivation to learn and underst and data structures)
  • 10. 1.1.1 Define Data Structures Data Structure Operations • Traversing  Accessing each data element exactly once so that certain items in the data may be processed • Searching  Finding the location of the data element (key) in the structure • Insertion  Adding a new data element to the structure
  • 11. 1.1.1 Define Data Structures Data Structure Operations • Deletion  Removing a data element from the structure • Sorting  Arrange the data elements in a logical order (ascending/ descending) • Merging  Combining data elements from two or more data structures into one
  • 12. 1.1.2 Apply Stacks, Queues, Linked Lists in programming Stack • Based on the principle of Last In First Out (LIFO) • Used extensively at every level of a modern computer system (compiler etc.)
  • 13. 1.1.2 Apply Stacks, Queues, Linked Lists in programming Stack • It is named stack as it behaves like a real-world stack. For example – a stack of books or a pile of plates, etc.
  • 14. 1.1.2 Apply Stacks, Queues, Linked Lists in programming Stack Representation • The following diagram depicts a stack and its operations.
  • 15. 1.1.2 Apply Stacks, Queues, Linked Lists in programming Stack Operations • Peek: If the stack is not empty, return its top element. • Pop: If the stack is not empty, delete and return its top element.
  • 16. 1.1.2 Apply Stacks, Queues, Linked Lists in programming Stack Operations • Push: Add a given element to the top of the stack. • Size: Return the number of elements in the stack.
  • 17. 1.1.2 Apply Stacks, Queues, Linked Lists in programming UML Diagram Translate into a Java interface Stack.java <<interface>> Stack +peek(): Object +pop(): Object +push(Object) +size(): int
  • 18. 1.1.2 Apply Stacks, Queues, Linked Lists in programming Stack Example: … Stack crates = new ArrayStack(4); crates.push(“CARROT”); crates.push(“ORANGES”); crates.push(“RAISIN”); crates.pop(); crates.pop(); crates.push(“PEACH”); crates.push(“BANANAS”); crates.pop();
  • 19. 1.1.2 Apply Stacks, Queues, Linked Lists in programming Stack Example: CARROT ORANGE CARROT ORANGE CARROT RAISIN ORANGE CARROT CARROT PEACH CARROT PEACH CARROT BANANAS
  • 20. 1.1.2 Apply Stacks, Queues, Linked Lists in programming Stack Exercise: Stack stack= new ArrayStack(); stack.push(“Monday”); stack.push(“Tuesday”); stack.push(“Wednesday”); stack.pop(); stack.pop(); stack.push(“Thursday”); stack.push(“Friday”); stack.pop(); stack.push(“Saturday”); stack.push(“Sunday”); stack.pop(); stack.pop();
  • 21. 1.1.2 Apply Stacks, Queues, Linked Lists in programming Stack Answer: Thursday Monday
  • 22. 1.1.2 Apply Stacks, Queues, Linked Lists in programming An Array Implementation • Several way to implement stack interface. • Simplest way is to use an ordinary array.
  • 23. 1.1.2 Apply Stacks, Queues, Linked Lists in programming An Array Implementation <<interface>> Stack +peek() :Object +pop() :Object +push(Object) +size() :int ArrayStack -a :Object[] -size :int +ArrayStack(int) +isEmpty():boolean +peek() :Object +pop() :Object +push(Object) +size() :int -resize()
  • 24. 1.1.2 Apply Stacks, Queues, Linked Lists in programming An Array Implementation Stack.java ArrayStack.java TestArrayStack.java
  • 25. 1.1.2 Apply Stacks, Queues, Linked Lists in programming An Array Implementation (refer to ArrayStack.java) • ArrayStack implementation uses a backing array a[] to store the stack’s elements. • Its other field is the integer size, which keeps a count of the number of elements in the stack.
  • 26. 1.1.2 Apply Stacks, Queues, Linked Lists in programming An Array Implementation (refer to ArrayStack.java) • In addition to the four methods required by the interface, the class also includes a public isEmpty() method and a private resize() method.
  • 27. 1.1.2 Apply Stacks, Queues, Linked Lists in programming An Array Implementation (refer to ArrayStack.java) • The latter is called by push() when the array is full. • Its rebuild the array, doubling its size. • This is done by declaring a temporary reference aa[] to the array in line 35.
  • 28. 1.1.2 Apply Stacks, Queues, Linked Lists in programming An Array Implementation (refer to ArrayStack.java) • Redefining a[] as a new array with twice the length in line 36. • Using the arraycopy() method of the system class to copy all the stack elements from aa[] back to a[] in line 37.
  • 29. 1.1.2 Apply Stacks, Queues, Linked Lists in programming An Array Implementation (refer to ArrayStack.java) • The peek() and pop() methods required that the stack be not empty. • This constrain enforce at line 14 and 19.
  • 30. 1.1.2 Apply Stacks, Queues, Linked Lists in programming An Array Implementation (refer to ArrayStack.java) • Note at line 21 the pop() method resets to null the array element that references the object being remove from the stack.
  • 31. 1.1.2 Apply Stacks, Queues, Linked Lists in programming An Array Implementation (refer to ArrayStack.java) • This prevents an unreachable reference from being maintain. • This class is tested in TestArrayStack.java
  • 32. 1.1.2 Apply Stacks, Queues, Linked Lists in programming Queue • is a data structure that implements the first-in-first-out (FIFO) protocol. • The only access point in the structure are at its ends where the elements are inserted and removed.
  • 33. 1.1.2 Apply Stacks, Queues, Linked Lists in programming Queue • Insertions are always made at the back of the queue. • Removals are always made at the front.
  • 34. 1.1.2 Apply Stacks, Queues, Linked Lists in programming Queue • The queue data structure abstracts the notion of an ordinary waiting line such as a line of people waiting to purchase admission tickets.
  • 35. 1.1.2 Apply Stacks, Queues, Linked Lists in programming Queue Operations • Add: Insert a given element at the back of the queue. • First: If the queue is not empty, return the element that is at the front of the queue.
  • 36. 1.1.2 Apply Stacks, Queues, Linked Lists in programming Queue Operations • Remove: If the queue is not empty, delete and return the element that is at the front of the queue. • Size: Return the number of elements in the queue.
  • 37. 1.1.2 Apply Stacks, Queues, Linked Lists in programming Queue Operations Translate into a Java interface Queue.java <<interface>> Queue +add(object) +first(): object +remove(): object +size(): int
  • 38. 1.1.2 Apply Stacks, Queues, Linked Lists in programming Queue Example: … Queue queue = new ArrayQueue(); queue.add(“CARROT”); queue.add(“ORANGES”); queue.add(“RAISIN”); queue.remove(); queue.remove(); queue.add(“PEACH”); queue.add(“BANANAS”); queue.remove(); queue.add(“DURIAN”); queue.add(“GRAPES”); queue.remove(); queue.remove();
  • 39. 1.1.2 Apply Stacks, Queues, Linked Lists in programming Stack Example: CARROT ORANGECARROT RAISINORANGECARROT RAISINORANGE RAISIN PEACHRAISIN BANANASPEACHRAISIN BANANASPEACH DURIANBANANASPEACH DURIANBANANASPEACH GRAPES
  • 40. 1.1.2 Apply Stacks, Queues, Linked Lists in programming Stack Example: DURIANBANANAS GRAPES DURIAN GRAPES
  • 41. 1.1.2 Apply Stacks, Queues, Linked Lists in programming Queue Exercise: … Queue queue = new ArrayQueue(); queue.add(“MONDAY”); queue.add(“TUESDAY”); queue.add(“SUNDAY”); queue.remove(); queue.remove(); queue.add(“WEDNESDAY”); queue.add(“SATURDAY”); queue.remove(); queue.remove(); queue.add(“THURSDAY”); queue.add(“FRIDAY”); queue.remove(); queue.remove();
  • 42. 1.1.2 Apply Stacks, Queues, Linked Lists in programming Queue Answer: Friday
  • 43. 1.1.2 Apply Stacks, Queues, Linked Lists in programming An Queue Implementation • Several way to implement queue interface. • Simplest way is to use an array as we did with the ArrayStack implementation of the Stack interface.
  • 44. 1.1.2 Apply Stacks, Queues, Linked Lists in programming An Queue Implementation • The simplest alternative way to an array implementation is a linked implementation.