List Operations 15 111 Advanced Programming Ananda Gunawardena
- Slides: 20
List Operations 15 -111 Advanced Programming Ananda Gunawardena 11/29/2020 1
Advantages of Linked Lists • The advantages of linked lists include: – Overflow can never occur unless the memory is actually full. – Insertions and deletions are easier than for contiguous (array) lists. – With large records, moving pointers is easier and faster than moving the items themselves. 11/29/2020 2
Disadvantage of Linked Lists • The disadvantages of linked lists include: – The pointers require extra space. – Linked lists do not allow random access. – Time must be spent traversing and changing the pointers. – Programming is typically trickier with pointers. 11/29/2020 3
Linked List Operations 11/29/2020 4
List Operations • Basic Operations on a Linked List are – Insertion – Deletion • Other operations include – build list – Append and prepend (special cases of insert) – empty – length – to. String – traversing 11/29/2020 5
List Traversal head null 11/29/2020 6
Insertion • Two cases to consider head – List is empty • Insert to the beginning of the list – List is non-empty • Locate the place to insert • Manipulate the references to make new links 11/29/2020 7
Insert Operation P New node 11/29/2020 8
Delete Operation P 11/29/2020 Node 9
Other Operations 11/29/2020 10
Prepend head null New node 11/29/2020 Insert to the beginning of the list 11
Append head null New node 11/29/2020 Insert to the end of the list 12
Length head null 11/29/2020 Insert to the end of the list 13
List Types 11/29/2020 14
Doubly Linked Lists • Typically a linked list with two pointers (next and previous) is called a doubly linked list head class Node { Object data; Node next; Node previous; …. . } 11/29/2020 15
Inserting into a Doubly Linked List • We have to manipulate both next and previous pointers. Insert new node N between P and Q Node P Node Q Node R Node N 11/29/2020 16
Deleting from a Doubly Linked List • Write the code to delete Node Q Node P 11/29/2020 Node Q Node R 17
Building a Doubly Linked List • Build a doubly linked list with 3 nodes (always insert to the front of the list) • Node Head = new Node(new Integer(3), null); • Node N = new Node(new Integer(4), null); • Connect the two nodes 11/29/2020 18
Make it a Circular Doubly Linked List • Write the code to create a circular doubly linked list. 11/29/2020 19
Multi Linked List - An Example 11/29/2020 20
- Ananda gunawardena
- Lani gunawardena
- 011 101 110
- Ananda sabil hussein
- Ananda aged care
- Dynamic programming bottom up
- Advanced internet programming
- A simple assembly scheme in system software
- Language processor
- Advanced programming in java
- Linear programming in operations management
- Operations management linear programming
- Operations management linear programming
- Linear programming in operation research
- Perbedaan linear programming dan integer programming
- Greedy vs dynamic
- System programming
- Linear vs integer programming
- Programing adalah
- List three examples of in-transit foodservice operations.
- Instruction list programming