You are on page 1of 24

Computer and Information Technology for (HKCEE) Module A1

10.1Features of Array
10.2 Features of Linked List
10.3 Comparison Between Array and Linked
List
10.4 Features of a Queue
10.5 Features of a Stack
10.6 Comparison Between Queue and Stack
Computer and Information
Technology for (HKCEE)
Module A1: Part C

10.1 Features of Array


One-dimensional array
a structured collection of components that can be
accessed individually by specifying the position of a
component with a single index value
General form of declaration
Type var_name[size];
e.g. char t[10];

© Longman Hong Kong Education Page2


Computer and Information
Technology for (HKCEE)
Module A1: Part C

10.1 Features of Array


One-dimensional array
C Program loading an integer array with 0 to 9
main()
{
int t,x[10];
for (t=1; t<11; ++t)
x[t]=t;
}

© Longman Hong Kong Education Page3


Computer and Information
Technology for (HKCEE)
Module A1: Part C

10.1 Features of Array


Two-dimensional array
an array of one-dimensional arrays
General form of declaration
Type array_name[2nd dimension size]
[1st dimension size];
e.g. int num[3][4];

© Longman Hong Kong Education Page4


Computer and Information
Technology for (HKCEE)
Module A1: Part C

10.1 Features of Array


Two-dimensional array
C Program loading with 1 to 12
main()
{
int t, i, num[3][4];
for (t=0; t<3; t++)
for (i=0; i<4; i++)
num[t][i] = (t*4) + i + 1;
}

© Longman Hong Kong Education Page5


Computer and Information
Technology for (HKCEE)
Module A1: Part C

10.1 Features of Array


Two-dimensional array

© Longman Hong Kong Education Page6


Computer and Information
Technology for (HKCEE)
Module A1: Part C

10.1 Features of Array


Unordered linear array
data items are held in no particular order
item added: append at the last term
item deleted: the following items are shifted to fill
the gap
Searching method: sequential search

© Longman Hong Kong Education Page7


Computer and Information
Technology for (HKCEE)
Module A1: Part C

10.1 Features of Array


Ordered linear array
data items are stored in ascending or descending
order
insertion or deletion of item: shifting of the current
items to keep the array in order
Searching method: binary search

© Longman Hong Kong Education Page8


Computer and Information
Technology for (HKCEE)
Module A1: Part C

10.2 Features of Linked List


Linked list
ordered collection of data in which each element
contains the location of the next element
consist of data and link
data
contain the useful information
contain the data to be processed
link
chain the data together
contain a pointer that identifies the next node in the list

© Longman Hong Kong Education Page9


Computer and Information
Technology for (HKCEE)
Module A1: Part C

10.2 Features of Linked List


List header
contain a pointer to the first element in the list
Null pointer
located at the last element
indicate the end of the data or point back to the
head of the list

© Longman Hong Kong Education Page10


Computer and Information
Technology for (HKCEE)
Module A1: Part C

10.2 Features of Linked List

© Longman Hong Kong Education Page11


Computer and Information
Technology for (HKCEE)
Module A1: Part C

10.2 Features of Linked List


Advantage of linked list
elements may be inserted and deleted by making
use of pointers
Free list
a list of empty elements
Additions to the linked lists
remove the first element from the free list
insert or append the element to the linked list
deleted element is added back to the front of the
free list (garbage collection)

© Longman Hong Kong Education Page12


Computer and Information
Technology for (HKCEE)
Module A1: Part C

10.3 Comparison Between Array and


Linked List
Size
array: static, fixed-size, bound
linked list: dynamic, variable-size, unbound
Access method
array: allow direct read or write access to any
array element
linked list: allow access by navigating from first
element to the target element

© Longman Hong Kong Education Page13


Computer and Information
Technology for (HKCEE)
Module A1: Part C

10.3 Comparison Between Array and


Linked List
Insert / delete
array: poor performed
linked list: well performed
Search speed
array: sequential search – unordered array
binary search – ordered array
linked list: sequential search only

© Longman Hong Kong Education Page14


Computer and Information
Technology for (HKCEE)
Module A1: Part C

10.3 Comparison Between Array and


Linked List
Ease of use
array: easy and simple
linked list: difficult
Use of storage
array: inefficient – high wastage when most of the
elements in the large-size array are empty
linked list: efficient – every elements are used

© Longman Hong Kong Education Page15


Computer and Information
Technology for (HKCEE)
Module A1: Part C

10.4 Features of a Queue


Queue
insertions are made at rear
deletions are made at front
a First-In, First-Out (FIFO) process
Advantages of a queue
multiple request are kept in a queue
a single resource is shared

© Longman Hong Kong Education Page16


Computer and Information
Technology for (HKCEE)
Module A1: Part C

10.4 Features of a Queue


Queue operations
Enqueue: insert operation on queue
Dequeue: remove operation on queue

© Longman Hong Kong Education Page17


Computer and Information
Technology for (HKCEE)
Module A1: Part C

10.4 Features of a Queue


Queue operations

© Longman Hong Kong Education Page18


Computer and Information
Technology for (HKCEE)
Module A1: Part C

10.5 Features of a Stack


Stack
insertions and deletions are made from the top only
a Last-In, First-Out (LIFO) process
Stack Operations
Push: insert operations on stacks
Pop: delete operations on stacks
useful in recursive programs, calling procedures
and functions

© Longman Hong Kong Education Page19


Computer and Information
Technology for (HKCEE)
Module A1: Part C

10.5 Features of a Stack


Stack Operations

© Longman Hong Kong Education Page20


Computer and Information
Technology for (HKCEE)
Module A1: Part C

10.6 Comparison Between Queue


and Stack
Usage
Queue: common
Stack: few
Structure
Queue: simple linear data structure; grows in one
direction (lengthy queue)
Stack: simple linear data structure; grows in one
direction (pushdown stack)

© Longman Hong Kong Education Page21


Computer and Information
Technology for (HKCEE)
Module A1: Part C

10.6 Comparison Between Queue


and Stack
Size
Queue: length of queue
Stack: depth of a stack
Type
Queue: First-In, First-Out (FIFO)
Stack: Last-In, First-Out (LIFO)

© Longman Hong Kong Education Page22


Computer and Information
Technology for (HKCEE)
Module A1: Part C

10.6 Comparison Between Queue


and Stack
Examples of Usage
Queue: print jobs in printing queue
Stack: calling procedures and functions

© Longman Hong Kong Education Page23


Computer and Information Technology for (HKCEE) Module A1

END

You might also like