final presentation for data structure
Post on 15-Apr-2017
15 Views
Preview:
TRANSCRIPT
Outline Introduction TRAVERSING A LINKED LIST SEARCHING A LINKED LIST Insertion Description Deletion Description Basic Node Implementation
What is link list ?
Link list is the linear collection of data elements called nodes,where the linear order is given by means of pointers.
Type of link lists
There are mainly two type of link list
Single link listDouble link listCircular link list
14
Traversing a SLL
The following method traverses a list (and prints its elements):
public void printFirstToLast(Node here) { while (here != null) { System.out.print(here.value + " ");
here = here.next;
}}
You would write this as an instance method of the Node class
Insertion Description
Insertion at the top of the list Insertion at the end of the list Insertion in the middle of the list
Insertion Description
Follow the previous steps and we get
48 17 142head //
head 93
Step 1 Step 2
Step 3
Insertion in the middle
Steps: Create a Node Set the node data Values Break pointer connection Re-connect the pointers
22
Inserting after (animation)
threetwoone
numerals
2.5node
Find the node you want to insert afterFirst, copy the link from the node that's already in the list
Then, change the link in the node that's already in the list
Deleting from the end
Steps Break the pointer connection Set previous node pointer to NULL Delete the node
Deleting from the Middle
Steps Set previous Node pointer to next node Break Node pointer connection Delete the node
Basic Node Implementation
The following code is written in C++:
Struct Node{
int data; //any type of data could be another structNode *next; //this is an important piece of code “pointer”
};
top related