Presentation is loading. Please wait.

Presentation is loading. Please wait.

JAVA & Linked List Implementation

Similar presentations


Presentation on theme: "JAVA & Linked List Implementation"— Presentation transcript:

1 JAVA & Linked List Implementation
Group VI Presented by Regulapati Venkata Ramana Rao

2 Objective Purpose Types of linked list Organization
Different operations Bio-Oh of each operation Case study

3 Introduction Is the linear data structure represented by nodes
Is an alternative to the contiguous array implementation It Consists of collection of connected , dynamically allocated Nodes Each node will have at least two elements Element itself The link to the next node in the list Link to next node Element 11 12

4 Introduction Class ListNode { Linked List Node Representation
Object element; ListNode nextNode; }

5 Introduction Why Linked List ?
Inserting or deleting of an item into/from list is easy, where as it requires extensive data movement if we use arrays Insertion Into Sorted Array Insert 4 into above array Increase the array size Locate the position of 4. Big-oh is O(N) Move the elements by one position. Big-oh is O(N) So Big-Oh is O(N2) 1 2 3 5 6 7

6 Introduction Array After Inserting Linked List Implementation
Inserting Element 4 Create new node with element 4 ListNode tmp = new ListNode(); tmp.element = 4; Search the position of element Big-Oh(N) 1 2 3 4 5 6 7 header 1 2 5 6 tmp 4

7 Introduction Insertion… Note: So Linked list is efficient in this case
Point the new node link to the node after the new node temp.next = current.next; Point the previous node link to new node current.next = tmp; Big-Oh is O(N) Note: So Linked list is efficient in this case current 1 2 5 6 tmp 4

8 Types Linked Lists are 3 types Single Linked List
Consists of data element and reference to the next Node in the Linked list First node is accessed by reference (Header Node) Last node is set to NULL Head 11 12 13

9 Types Double Linked List
Consists of nodes with two link members one points to the previous and other to the next node Maximizes the needs of list traversals Compared to the Singled list inserting and deleting nodes is a bit slower as both the links has to be updated It requires the extra storage space for the second link Head 11 11 11

10 Types Circular Linked list
Similar to the doubly linked list, but the last node link points to the first node instead of null Useful in algorithms where there is no particular first or last item Advantage is we can make head to point any node without destroying the list Operations are similar to single linked list except identifying the last node in the list. To find the last node compare the last node to head node (i.e you have found the last node if its link points to the same node that the head points)

11 Types Circularly Linked List Representation first 11 12 13

12 Header & Trailer Nodes Header Node: A placeholder node at the beginning of list, used to simplify list processing.It doesn’t hold any data but satisfies that the every node has a previous node. Trailer Node: A placeholder node at the end of list, used to simplify list processing

13 Single LinkedList Operations
Insertion of node Consider 3 cases of insertion Node is first node in the linked list Node is an inner node Node is last node Deleting specific node Printing/Traversing Liked List Find specific node Find Length of Linked List

14 Implementation All the above mentioned operations are implemented on a sorted singly linked list in the following example The implementation has these classes List.java … This is the interface LinkedList.java … Implementation for the methods declared in interface Node.java … This is actual Node in Linked list and also has Accessor / Mutator methods TestLinkedList.java … Test client program

15 List.java Interface

16 Node.java

17 Node.java

18 LinkedList.java //This class Implements the List interface

19 LinkedList.java

20 LinkedList.java

21 LinkedList.java

22 LinkedList.java

23 LinkedList.java

24 LinkedList.java

25 InvalidElementException.java

26 ClientLinkedList.java

27 ClientLinkedList.java

28 ClientLinkedList.java


Download ppt "JAVA & Linked List Implementation"

Similar presentations


Ads by Google