Lists
Lists
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
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.