0% found this document useful (0 votes)
10 views2 pages

Lists

Uploaded by

Jake Waters
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Lists

Uploaded by

Jake Waters
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Interface

Lists
Abstraction
- A list is another example of an Abstract Data Type. An abstract data
Implementation
type allows us to view the data and perform operations that are allowed
without regard to how they will be implemented.

Dynamic vs Static
- A static data structure cannot change size after it has been created.
- A dynamic data structure can grow or shrink
- Programming languages often have an inbuilt dynamic list
- Python, Java, VB.NET and a few others have dynamic list support.

Implementation
- The information of an inbuilt list ADT is hidden from user
- A new location is taken from “heap” = memory locations used for dynamic allocation
- When an item is deleted, the memory location is freed p and returned to the “heap”
- A system of pointers keeps the list in the order specified by the user.

Application of Lists
- School Timetable
- Transport Schedules
- Grades
- Results of Sporting Events
- Leader-boards
- Menus

Programming Operations
List operation Operation
isEmpty() Test for an empty list
Append(item) Add a new item at the end of the list
Remove(Item) Remove first occurrence of an item from list
Count(Item) Return the number of occurrences of item in lst
Len(Item) Return the number of items in the list
Index(Item) Return the position of item
Insert(pos,item) Add a new item at position pos
Pop() Remove and return the last item in the list
Pop(pos) Remove and return the item at position pos

Sorting a List
- In python, there is a built-in method for sorting a list, which you can try in interactive mode

Implementing a queue as a list


- Using dynamic data structure such as list to implement a queue.
- We do not need to use any functions for a list; this is because a list is dynamic.
Linked Lists
- A dynamic abstract data structure which can be implemented as an array and pointers,
composed of “nodes”.
- Each node is composed of two parts:
o The data (which may be a complex data structure)
o A pointer (the index) of the next code
- A start pointer identifies the first node in the list
- A nextfree pointer shows the index of the net free pace in the array.

Dynamic Data Structure – A data structure where the size and shape can change.

Array Implementation
- The empty array is initialised as a linked list of free spaces
- Start will point to the first element in the list.

Index Data Pointer Index Data Pointer


0 1 0 Nancy Null
1 2 1 2
2 3 2 3
3 4 3 4
4 null 4 null
Start = Null Nextfree = 0 Start = 0 Nextfree = 1

Index Data Pointer Index Data Pointer


0 Nancy Null 0 Nancy Null
1 Ava 0 1 Ava 2
2 3 2 Dave 0
3 4 3 4
4 null 4 null
Start = 1 Nextfree = 2 Start = 1 Nextfree = 3

Index Data Pointer


0 Nancy 3
1 Ava 2
2 Dave 0
3 Peter null
4 null
Start = 1 Nextfree = 4

You might also like