Adts and List As Adt
Adts and List As Adt
Grocery list
And so on
List as an ADT
A list is a collection of homogenous elements
Length of list is 4.
Maximum number of elements is 6.
Remember array and list are different things; array can be
used only as a data container for storing list elements
Data A B C D
Index 0 1 2 3 4 5
CreateList (MAX_ELEMENTS)
► Function : Initializes List to empty state
► Input : MAX_ELEMENTS
► Precondition : None
► Output : List
DestroyList (List)
► Function : Destroys all elements , leaving List in empty state.
► Input : List
► Input : List
► Output : true/false
► Input : List
► Output : true/false
► Input : List
NewElement(ListElementType)
► Output : List
ModifyElement(List, ModElement)
► Function : Replace existing list element with same key as
ModElement.
► Input : List,
ModElement(ListElementType)
► Output : List
DeleteElement(List,DeleteVal)
► Function : Deletes the element containing the key
DeleteVal from list.
► Input : List
DeleteVal(KeyType)
► Output : List
PrintList(List)
► Function : Prints all the element in List in order from
smallest to largest key value.
► Input : List
Array-based implementation
Linked-list based implementation
► Singly linked list
► Circular linked list
► Doubly linked list
19
20
2. Insertion at a Particular
Position: A user may insert an
item at a particular position in a list.
► Requires a utility method,
makeRoom()to shift elements
towards right.
► Then the new value is inserted at
the vacated position.
23
List of length 5
Position in 1 2 3 4 5
the list
Index 0 1 2 3 4 5
Value 8 20 33 44 48
24
Insert Carla as 3rd position in the list
Search Operation
25 Searches a value in a non-empty list.
If found, returns position of the element in the list (not in
array).
If not found, returns a special invalid position e.g. -1.
List of length 5
Position in 1 2 3 4 5
the list
Index 0 1 2 3 4 5
Value 8 20 33 44 48