Title: CSI 1340 Introduction to Computer Science II
1CSI 1340Introduction to Computer Science II
- Chapter 5
- Linked Structures
2Stack ImplementationAs A Linked Structure
3- struct NodeType
-
- ItemType info
- NodeType next
-
- NodeType topPtr
- NOTE topPtr is a pointer capable of pointing at
NodeType nodes
info
next
50
topPtr
4Linked Structure
(topPtr).next
topPtr-gtnext
50
topPtr
75
NULL
topPtr-gtinfo
(topPtr).info
5- include ItemType.h
- struct NodeType
-
- ItemType info
- NodeType next
-
- class StackType // Stack as a linked structure
-
- public
- . . .
- private
- NodeType topPtr
topPtr
6- . . .
- class StackType // Stack implementation using a
- // linked structure
- public
- StackType( )
- void MakeEmpty( )
- void Push(ItemType newItem)
- void Pop(ItemType item)
- bool IsEmpty( ) const
- bool IsFull( ) const
7NULL Pointer
- A pointer that points to nothing.
- topPtr NULL
- Requires the header file called ltcstddefgt
- include ltcstddefgt
- Can be used to identify an empty stack.
8- include Stack.h
- StackTypeStackType( ) // default constructor
-
- topPtr NULL
NULL
topPtr
9- bool StackTypeIsEmpty( ) const
-
- return (topPtr NULL)
NULL
topPtr
10Pushing a Node onto anEmpty Stack
11- void StackTypePush(ItemType newItem)
-
- NodeType location
-
location
12- void StackTypePush(ItemType newItem)
-
- NodeType location
- location new NodeType
location
info next
location
13- void StackTypePush(ItemType newItem)
-
- NodeType location
- location new NodeType
- location-gtinfo newItem
location
info next
location
85
location
14- void StackTypePush(ItemType newItem)
-
- NodeType location
- location new NodeType
- location-gtinfo newItem
- location-gtnext topPtr
location
info next
location
location
85
85
location
NULL
NULL
topPtr
15- void StackTypePush(ItemType newItem)
-
- NodeType location
- location new NodeType
- location-gtinfo newItem
- location-gtnext topPtr
- topPtr location
-
location
info next
location
location
85
85
location
NULL
topPtr
16Stack After A Push Operation
topPtr
85
NULL
17Pushing a Node onto a Stackthat Contains At
Least One Node
18- void StackTypePush(ItemType newItem)
-
- NodeType location
-
location
19- void StackTypePush(ItemType newItem)
-
- NodeType location
- location new NodeType
location
info next
location
20- void StackTypePush(ItemType newItem)
-
- NodeType location
- location new NodeType
- location-gtinfo newItem
location
info next
location
50
location
21- void StackTypePush(ItemType newItem)
-
- NodeType location
- location new NodeType
- location-gtinfo newItem
- location-gtnext topPtr
location
info next
location
50
location
50
location
85
topPtr
NULL
22- void StackTypePush(ItemType newItem)
-
- NodeType location
- location new NodeType
- location-gtinfo newItem
- location-gtnext topPtr
- topPtr location
-
location
info next
location
50
location
50
location
85
topPtr
NULL
23Stack After a Second Push
topPtr
85
NULL
50
24Popping a Node from a Stackthat Contains More
than One Node
25- void StackTypePop(ItemType item)
-
- NodeType tempPtr
-
tempPtr
26- void StackTypePop(ItemType item)
-
- NodeType tempPtr
- item topPtr-gtinfo
-
tempPtr
50
item
27- void StackTypePop(ItemType item)
-
- NodeType tempPtr
- item topPtr-gtinfo
- tempPtr topPtr
-
tempPtr
50
item
tempPtr
topPtr
85
NULL
50
28- void StackTypePop(ItemType item)
-
- NodeType tempPtr
- item topPtr-gtinfo
- tempPtr topPtr
- topPtr topPtr-gt next
tempPtr
50
item
tempPtr
topPtr
85
NULL
50
29- void StackTypePop(ItemType item)
-
- NodeType tempPtr
- item topPtr-gtinfo
- tempPtr topPtr
- topPtr topPtr-gt next
- delete tempPtr
-
tempPtr
50
item
tempPtr
topPtr
?
85
NULL
30Stack After a Pop Operation
topPtr
85
NULL
31Popping a Node from a Stackthat Contains Only
One Node
32- void StackTypePop(ItemType item)
-
- NodeType tempPtr
-
tempPtr
33- void StackTypePop(ItemType item)
-
- NodeType tempPtr
- item topPtr-gtinfo
-
tempPtr
85
item
topPtr
85
NULL
34- void StackTypePop(ItemType item)
-
- NodeType tempPtr
- item topPtr-gtinfo
- tempPtr topPtr
tempPtr
85
item
tempPtr
topPtr
85
NULL
35- void StackTypePop(ItemType item)
-
- NodeType tempPtr
- item topPtr-gtinfo
- tempPtr topPtr
- topPtr topPtr-gtnext
tempPtr
85
item
tempPtr
topPtr
NULL
85
NULL
36- void StackTypePop(ItemType item)
-
- NodeType tempPtr
- item topPtr-gtinfo
- tempPtr topPtr
- topPtr topPtr-gtnext
- delete tempPtr
-
tempPtr
85
item
tempPtr
topPtr
?
NULL
37Make Empty
- Is there an easy way to do it?
38- void StackTypeMakeEmpty( )
-
- ItemType dummy
- while (!IsEmpty( ))
- Pop(dummy)
39- StackTypeMakeEmpty( )
-
- NodeType tempPtr
tempPtr
topPtr
85
NULL
50
40- StackTypeMakeEmpty( )
-
- NodeType tempPtr
- while (topPtr ! NULL)
-
tempPtr
topPtr
85
NULL
50
41- StackTypeMakeEmpty( )
-
- NodeType tempPtr
- while (topPtr ! NULL)
-
- tempPtr topPtr
tempPtr
topPtr
85
NULL
50
42- StackTypeMakeEmpty( )
-
- NodeType tempPtr
- while (topPtr ! NULL)
-
- tempPtr topPtr
- topPtr topPtr-gtnext
tempPtr
topPtr
85
NULL
50
43- StackTypeMakeEmpty( )
-
- NodeType tempPtr
- while (topPtr ! NULL)
-
- tempPtr topPtr
- topPtr topPtr-gtnext
- delete tempPtr
-
tempPtr
topPtr
?
85
NULL
44Stack After Deleting First Node
topPtr
85
NULL
45- StackTypeMakeEmpty( )
-
- NodeType tempPtr
- while (topPtr ! NULL)
-
-
-
tempPtr
topPtr
85
NULL
46- StackTypeMakeEmpty( )
-
- NodeType tempPtr
- while (topPtr ! NULL)
-
- tempPtr topPtr
-
tempPtr
topPtr
85
NULL
47- StackTypeMakeEmpty( )
-
- NodeType tempPtr
- while (topPtr ! NULL)
-
- tempPtr topPtr
- topPtr topPtr-gtnext
tempPtr
topPtr
85
NULL
NULL
48- StackTypeMakeEmpty( )
-
- NodeType tempPtr
- while (topPtr ! NULL)
-
- tempPtr topPtr
- topPtr topPtr-gtnext
- delete tempPtr
-
tempPtr
topPtr
?
NULL
49Stack After Deleting Last Node
topPtr
NULL
50Why is a destructor needed?
- When a local stack variable goes out of scope,
the memory space for data member topPtr is
deallocated. But the nodes that topPtr points to
are not automatically deallocated. - A class destructor is used to deallocate the
dynamic memory pointed to by the data member.
51- StackTypeStackType( )
-
- MakeEmpty( )
-
52- bool StackTypeIsFull( ) const
-
- NodeType location
location
53- bool StackTypeIsFull( ) const
-
- NodeType location
- location new NodeType // Returns NULL if heap
is depleted
location
54- bool StackTypeIsFull( ) const
-
- NodeType location
- location new NodeType // Returns NULL if heap
is depleted
NULL
location
55- bool StackTypeIsFull( ) const
-
- NodeType location
- location new NodeType // Returns NULL if heap
is depleted - if (location NULL)
- return TRUE
NULL
location
56- bool StackTypeIsFull( ) const
-
- NodeType location
- location new NodeType // Returns NULL if heap
is depleted - if (location NULL)
- return TRUE
- else
-
location
57- bool StackTypeIsFull( ) const
-
- NodeType location
- location new NodeType // Returns NULL if heap
is depleted - if (location NULL)
- return TRUE
- else
-
- delete location
-
location
?
58- bool StackTypeIsFull( ) const
-
- NodeType location
- location new NodeType // Returns NULL if heap
is depleted - if (location NULL)
- return TRUE
- else
-
- delete location
- return FALSE
-
location
?
59Comparing Stack Implementations
60Stack Comparisons
- Ways of comparing implementations
- Storage requirements
- Efficiency of the algorithms (Big-O)
61Storage Requirements for Stack Implementation
- Array-based - implementation takes the same
amount of memory (maximum possible), no matter
how many locations are actually used. - Linked-based - implementation only requires space
for the actual number of elements used, but each
element is larger because both the pointer and
the data must be stored.
62Efficiency of Stack Operations (Big-O)
63Stack Constructor
- Array implementation Linked implementation
- StackTypeStackType( ) StackTypeStackType( )
-
- top -1 topPtr NULL
-
- O(1) O(1)
64MakeEmpty
- Array implementation Linked implementation
- void StackTypeMakeEmpty( ) void
StackTypeMakeEmpty( ) -
- top -1 NodeType tempPtr
- while (topPtr ! NULL)
-
- tempPtr topPtr
- topPtr topPtr-gtnext
- delete tempPtr
-
-
- O(1) O(N)
65Efficiency of Stack Operations (Big-O)
- Array Linked
- Class constructor O(1) O(1)
- MakeEmpty O(1) O(N)
- IsFull O(1) O(1)
- IsEmpty O(1) O(1)
- Push O(1) O(1)
- Pop O(1) O(1)
- Destructor O(1) O(N)
- Overall efficiency is roughly equivalent (because
MakeEmpty and the Destructor are usually not used
much)
66Advantages of Linked Implementation
- More flexible.
- Wastes less space when the number of stack items
can vary greatly and the stack size is small.
67Use a Linked Implementation when . . .
- The number of stack items can vary greatly.
- The stack size is totally unpredictable.
68Advantages of Array Implementation
- Short, simple, efficient.
- Executes faster if pushing and popping occur
frequently.
69Use an Array Implementation when . . .
- The exact number of stack items is known and will
not vary. - The language does not support dynamic memory
allocation.
70Queue ImplementationAs A Linked Structure
71- struct NodeType
-
- ItemType info
- NodeType next
-
- NodeType qFront
- NodeType qRear
qFront
qRear
72Linked Structure
qFront
qRear
qRear-gtnext
qFront-gtnext
C
A
NULL
qFront-gtinfo
qRear-gtinfo
73- include ItemType.h
- struct NodeType
-
- ItemType info
- NodeType next
-
- class QueType // Queue as a linked structure
-
- public
- . . .
- private
- NodeType qFront
- NodeType qRear
qFront
qRear
74- class QueType // Queue implementation using a
- // linked structure
- public
- QueType( )
- void MakeEmpty( )
- void Enqueue(ItemType newItem)
- void Dequeue(ItemType item)
- bool IsEmpty( ) const
- bool IsFull( ) const
75- include Queue.h
- include ltstddef.hgt // for NULL
- QueTypeQueType( ) // default constructor
-
- qFront NULL
- qRear NULL
NULL
qFront
NULL
qRear
76- bool QueTypeIsEmpty( ) const
-
- return (qFront NULL)
NULL
qFront
77Enqueuing a Node onto anEmpty Queue
78- void QueTypeEnqueue(ItemType newItem)
-
- NodeType newNode
-
newNode
79- void QueTypeEnqueue(ItemType newItem)
-
- NodeType newNode
- newNode new NodeType
newNode
newNode
80- void QueTypeEnqueue(ItemType newItem)
-
- NodeType newNode
- newNode new NodeType
- newNode-gtinfo newItem
newNode
newNode
C
newNode
81- void QueTypeEnqueue(ItemType newItem)
-
- NodeType newNode
- newNode new NodeType
- newNode-gtinfo newItem
- newNode-gtnext NULL
newNode
newNode
newNode
C
C
newNode
NULL
NULL
qFront
NULL
qRear
82- void QueTypeEnqueue(ItemType newItem)
-
- NodeType newNode
- newNode new NodeType
- newNode-gtinfo newItem
- newNode-gtnext NULL
- qFront newNode
newNode
newNode
newNode
C
C
newNode
NULL
qFront
NULL
qRear
83- void QueTypeEnqueue(ItemType newItem)
-
- NodeType newNode
- newNode new NodeType
- newNode-gtinfo newItem
- newNode-gtnext NULL
- qFront newNode
- qRear newNode
-
newNode
newNode
newNode
C
C
newNode
NULL
qFront
qRear
84Queue After an Enqueue Operation
qFront
C
NULL
qRear
85Enqueuing a Node onto a Queuethat Contains At
Least One Node
86- void QueTypeEnqueue(ItemType newItem)
-
- NodeType newNode
-
newNode
qFront
C
NULL
qRear
87- void QueTypeEnqueue(ItemType newItem)
-
- NodeType newNode
- newNode new NodeType
newNode
newNode
qFront
C
NULL
qRear
88- void QueTypeEnqueue(ItemType newItem)
-
- NodeType newNode
- newNode new NodeType
- newNode-gtinfo newItem
newNode
newNode
A
newNode
qFront
C
NULL
qRear
89- void QueTypeEnqueue(ItemType newItem)
-
- NodeType newNode
- newNode new NodeType
- newNode-gtinfo newItem
- newNode-gtnext NULL
newNode
newNode
newNode
A
A
newNode
NULL
qFront
C
NULL
qRear
90- void QueTypeEnqueue(ItemType newItem)
-
- NodeType newNode
- newNode new NodeType
- newNode-gtinfo newItem
- newNode-gtnext NULL
- qRear-gtnext newNode
newNode
newNode
newNode
A
A
newNode
NULL
qFront
C
qRear
91- void QueTypeEnqueue(ItemType newItem)
-
- NodeType newNode
- newNode new NodeType
- newNode-gtinfo newItem
- newNode-gtnext NULL
- qRear-gtnext newNode
- qRear newNode
-
newNode
newNode
newNode
A
A
newNode
NULL
qFront
C
qRear
92Queue After a Second Enqueue
qFront
A
NULL
C
qRear
93Comparing the Two Implementations
- void QueTypeEnqueue(ItemType newItem)
- // Empty queue // Queue with a node
- NodeType newNode NodeType newNode
- newNode new NodeType newNode new
NodeType - newNode-gtinfo newItem newNode-gtinfo
newItem - newNode-gtnext NULL newNode-gtnext NULL
- qFront newNode qRear-gtnext newNode
- qRear newNode qRear newNode
94Final Enqueue Implementation
- void QueTypeEnqueue(ItemType newItem)
-
- NodeType newNode
- newNode new NodeType
- newNode-gtinfo newItem
- newNode-gtnext NULL
- if (qRear NULL)
- qFront newNode
- else
- qRear-gtnext newNode
- qRear newNode
-
95Dequeuing a Node from a Queuethat Contains More
than One Node
96- void QueTypeDequeue(ItemType item)
-
- NodeType tempPtr
-
tempPtr
qFront
A
NULL
C
qRear
97- void QueTypeDequeue(ItemType item)
-
- NodeType tempPtr
- item qFront-gtinfo
-
tempPtr
C
item
qFront
A
NULL
C
qRear
98- void QueTypeDequeue(ItemType item)
-
- NodeType tempPtr
- item qFront-gtinfo
- tempPtr qFront
-
tempPtr
C
item
tempPtr
qFront
A
NULL
C
qRear
99- void QueTypeDequeue(ItemType item)
-
- NodeType tempPtr
- item qFront-gtinfo
- tempPtr qFront
- qFront qFront-gtnext
-
tempPtr
C
item
tempPtr
qFront
A
NULL
C
qRear
100- void QueTypeDequeue(ItemType item)
-
- NodeType tempPtr
- item qFront-gtinfo
- tempPtr qFront
- qFront qFront-gtnext
- delete tempPtr
-
tempPtr
C
item
tempPtr
qFront
?
A
NULL
qRear
101Queue After a Dequeue Operation
qFront
A
NULL
qRear
102Dequeuing a Node from a Queuethat Contains Only
One Node
103- void QueTypeDequeue(ItemType item)
-
- NodeType tempPtr
-
tempPtr
qFront
A
NULL
qRear
104- void QueTypeDequeue(ItemType item)
-
- NodeType tempPtr
- item qFront-gtinfo
-
tempPtr
A
item
qFront
A
NULL
qRear
105- void QueTypeDequeue(ItemType item)
-
- NodeType tempPtr
- item qFront-gtinfo
- tempPtr qFront
-
tempPtr
A
item
tempPtr
qFront
A
NULL
qRear
106- void QueTypeDequeue(ItemType item)
-
- NodeType tempPtr
- item qFront-gtinfo
- tempPtr qFront
- qFront qFront-gtnext
-
tempPtr
C
item
tempPtr
qFront
NULL
A
NULL
qRear
107- void QueTypeDequeue(ItemType item)
-
- NodeType tempPtr
- item qFront-gtinfo
- tempPtr qFront
- qFront qFront-gtnext
- delete tempPtr
- qRear NULL
-
tempPtr
C
item
tempPtr
qFront
?
NULL
qRear
108- void QueTypeDequeue(ItemType item)
-
- NodeType tempPtr
- item qFront-gtinfo
- tempPtr qFront
- qFront qFront-gtnext
- delete tempPtr
- qRear NULL
-
tempPtr
C
item
tempPtr
qFront
?
NULL
qRear
NULL
109Comparing the Two Implementations
- void QueTypeDequeue(ItemType item)
- // Queue with more than // Queue with only one
node - // one node
- NodeType tempPtr NodeType tempPtr
- item qFront-gtinfo item qFront-gtinfo
- tempPtr qFront tempPtr qFront
- qFront qFront-gtnext qFront qFront-gtnext
- delete tempPtr delete tempPtr
- qRear NULL
-
110Final Dequeue Implementation
- void QueTypeDequeue(ItemType item)
-
- NodeType tempPtr
- item qFront-gtinfo
- tempPtr qFront
- qFront qFront-gtnext
- if (qFront NULL)
- qRear NULL
- delete tempPtr
-
111IsFull
112- bool QueTypeIsFull( ) const
-
- NodeType ptr
- ptr new NodeType
- if (ptr NULL)
- return TRUE
- else
-
- delete ptr
- return FALSE
-
ptr
113MakeEmpty
114tempPtr
- void QueTypeMakeEmpty( )
-
- NodeType tempPtr
-
qFront
A
NULL
C
qRear
115tempPtr
- void QueTypeMakeEmpty( )
-
- NodeType tempPtr
- while (qFront ! NULL)
-
qFront
A
NULL
C
qRear
116tempPtr
- void QueTypeMakeEmpty( )
-
- NodeType tempPtr
- while (qFront ! NULL)
-
- tempPtr qFront
tempPtr
qFront
A
NULL
C
qRear
117tempPtr
- void QueTypeMakeEmpty( )
-
- NodeType tempPtr
- while (qFront ! NULL)
-
- tempPtr qFront
- qFront qFront-gtnext
-
tempPtr
qFront
A
NULL
C
qRear
118tempPtr
- void QueTypeMakeEmpty( )
-
- NodeType tempPtr
- while (qFront ! NULL)
-
- tempPtr qFront
- qFront qFront-gtnext
- delete tempPtr
-
tempPtr
qFront
?
A
NULL
qRear
119tempPtr
- void QueTypeMakeEmpty( )
-
- NodeType tempPtr
- while (qFront ! NULL)
-
- tempPtr qFront
- qFront qFront-gtnext
- delete tempPtr
-
tempPtr
qFront
A
NULL
qRear
120tempPtr
- void QueTypeMakeEmpty( )
-
- NodeType tempPtr
- while (qFront ! NULL)
-
- tempPtr qFront
- qFront qFront-gtnext
- delete tempPtr
-
tempPtr
qFront
A
NULL
NULL
qRear
121tempPtr
- void QueTypeMakeEmpty( )
-
- NodeType tempPtr
- while (qFront ! NULL)
-
- tempPtr qFront
- qFront qFront-gtnext
- delete tempPtr
-
tempPtr
qFront
?
NULL
qRear
122tempPtr
- void QueTypeMakeEmpty( )
-
- NodeType tempPtr
- while (qFront ! NULL)
-
- tempPtr qFront
- qFront qFront-gtnext
- delete tempPtr
-
- qRear NULL
-
tempPtr
qFront
?
NULL
qRear
NULL
123Queue After MakeEmpty
qFront
NULL
qRear
NULL
124Comparing Queue Implementations
125Queue Comparisons
- Ways of comparing implementations
- Storage requirements
- Efficiency of the algorithms (Big-O)
126Storage Requirementsfor Queue Implementations
- Array-based - implementation takes the same
amount of memory (maximum possible), no matter
how many locations are actually used. - Linked-based - implementation only requires space
for the actual number of elements used, but each
element is larger because both the pointer and
the data must be stored.
127Efficiency of Queue Operations (Big-O)
- Array Linked
- Class constructor O(1) O(1)
- MakeEmpty O(1) O(N)
- IsFull O(1) O(1)
- IsEmpty O(1) O(1)
- Enqueue O(1) O(1)
- Dequeue O(1) O(1)
- Destructor O(1) O(N)
- Overall efficiency is roughly equivalent (because
MakeEmpty and the Destructor are usually not used
much)
128Linked Implementation of a Unsorted List
129- include ItemType.h
- struct NodeType
-
- ItemType info
- NodeType next
-
- class UnsortedType // Unsorted list as a linked
structure -
- public
- . . .
- private
- int length
- NodeType listData
- NodeType currentPos
length
listData
currentPos
130- class UnsortedType // Unsorted list as a linked
structure -
- public
- UnsortedType( )
- UnsortedType(const UnsortedType source)
- UnsortedType( )
- void MakeEmpty( )
- bool IsFull( ) const
- int LengthIs( ) const
- . . .
- void GetNextItem(ItemType item)
131Default Constructor
- Initializes length to 0 and listData to NULL
132Destructor
- Deletes the nodes in the list (implementation
similar to stack) and sets length equal to 0
133MakeEmpty
- Implementation identical to destructor
134IsFull
- Implementation identical to stack and queue
135LengthIs
- Returns the value of length (i.e., return length)
136InsertItem
- Inserts an item at the front of the list
(implementation identical to stack) and
increments length
137DeleteItem
- Deletes a node in the list and decrements length
- Special cases that must be handled
- Delete the only node in the list
- Delete the first node in the list
- Delete a node between two nodes
- Delete the last node in the list
138Deleting the Last Node in a Unsorted List
139listData
15
30
20
NULL
3
listData
length
15
30
NULL
140listData
15
30
20
NULL
- // Need a pointer pointing to the node that will
be deleted - // (tempLocation) and one pointing to the node
that precedes - // it (location)
location
tempLocation
3
length
listData
15
30
NULL
141listData
15
30
NULL
20
NULL
- location-gtnext tempLocation-gtnext
location
tempLocation
3
length
listData
15
30
NULL
142listData
15
30
NULL
?
- location-gtnext tempLocation-gtnext
- delete tempLocation
location
tempLocation
3
length
listData
15
30
NULL
143listData
15
30
NULL
?
- location-gtnext tempLocation-gtnext
- delete tempLocation
- length--
location
tempLocation
2
length
listData
15
30
NULL
144Efficiency of Unsorted List Operations (Big-O)
145Big-O Comparisons of Unsorted List
- Array Linked
- Class constructor O(1) O(1)
- Destructor O(1) O(N)
- MakeEmpty O(1) O(N)
- IsFull O(1) O(1)
- LengthIs O(1) O(1)
- ResetList O(1) O(1)
- GetNextItem O(1) O(1)
- RetrieveItem O(N) O(N)
- InsertItem O(1) O(1)
- DeleteItem O(N) O(N)
146Linked Implementation of a Sorted List
147Member Function Implementations
- Implementations of the member functions are
identical to those for the unsorted list except
for InsertItem
148InsertItem
- Inserts the new item in the appropriate place in
the list and increments length - Special cases that must be handled
- Inserting a new first node
- Inserting between two nodes
- Inserting a new last node
- Inserting into an empty list
149Inserting a Node Between Two Nodes in a Sorted
List
150listData
15
60
85
NULL
- // Need a pointer pointing to the node that will
precede - // the new node (predloc) and one pointing to
the node that - // will follow the new node (location)
predloc
location
3
length
151listData
15
60
85
NULL
predloc
location
newNode
3
length
152listData
15
60
85
NULL
- NodeType newNode
- newNode new NodeType
predloc
location
newNode
3
length
153listData
15
60
85
NULL
- NodeType newNode
- newNode new NodeType
- newNode-gtinfo item
predloc
location
newNode
70
3
length
154listData
15
60
85
NULL
- NodeType newNode
- newNode new NodeType
- newNode-gtinfo item
- newNode-gtnext location
predloc
location
newNode
70
3
length
155listData
15
60
85
NULL
predloc
location
- NodeType newNode
- newNode new NodeType
- newNode-gtinfo item
- newNode-gtnext location
- predloc-gtnext newNode
newNode
70
3
length
156listData
15
60
85
NULL
predloc
location
newNode
70
- NodeType newNode
- newNode new NodeType
- newNode-gtinfo item
- newNode-gtnext location
- predloc-gtnext newNode
- length
4
length
157Efficiency of Sorted List Operations (Big-O)
158Big-O Comparisons of Sorted List
- Array Linked
- Class constructor O(1) O(1)
- Destructor O(1) O(N)
- MakeEmpty O(1) O(N)
- IsFull O(1) O(1)
- LengthIs O(1) O(1)
- ResetList O(1) O(1)
- GetNextItem O(1) O(1)
- RetrieveItem O(N) O(N)
- InsertItem O(N) O(N)
- DeleteItem O(N) O(N)
- O(log2N) if binary search is used Cannot do
binary search