Upcoming SlideShare
×

372 views
278 views

Published on

Published in: Education, Technology
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
372
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
19
0
Likes
0
Embeds 0
No embeds

No notes for slide

1. 1. Disclaimer: This presentation is prepared by trainees ofbaabtra as a part of mentoring program. This is not officialdocument of baabtra –Mentoring PartnerBaabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .Ltd
3. 3. Linked List• Consists of– Sequence of nodes.Each node contains a value and a link to some othernode.(pointer or reference)The last node will be having a link which points tonull.The list may or may not have a header.
5. 5. Linked List• Successor :successor of a node is the nodepointing next to that node.(suc(a)=b).• Predecessor: predecessor of a node is thenode pointing this node.(pre(b)=a).• The length of the linked list is the number ofnodes in it.
6. 6. Linked Lists• In programming languages like C,CPP we areusing “pointers ” to implement linked lists.• But in java programming, we use referencesinstead of pointers.• To some extent both are same , but thedifference is that C and CPP allows to modifypointers in anyways, and can point toanything.
7. 7. Creating references• Person p=new Person(“John”);the keyword ‘new’ creates the object andreturns a references.here new Person(“John”) creates the objectand returns a references to it.We can assign this reference to P.
8. 8. Creating linksA B C DClass node{node next;char value;Node(char value, node n) //constructor{value=value;next=n;}}
9. 9. Creating Links• Node temp=new node(D, null);• temp=new node(C,temp);• temp=new node(B,temp);• temp=new node(A,temp);• Temp=new node(null,temp);
10. 10. Single linked list• Each node will have a value and a link to thenext value(successor).• There will be a header which points either tothe first element of the list, or if the list isempty it will point to the null link.
11. 11. Singly Linked Lists(SLL)A B C D
12. 12. Traversing a SLL• The following method traverses a list and printits 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.