Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 30 trang
THÔNG TIN TÀI LIỆU
Cấu trúc
Singly Linked Lists
PowerPoint Presentation
Slide 3
Slide 4
Slide 5
Slide 6
Slide 7
Slide 8
Slide 9
Slide 10
Singly Linked Lists and Arrays
Class Node
Slide 13
Insertion of an Element at the Head
Slide 15
Slide 16
Deleting an Element at the Head
Slide 18
Slide 19
Insertion of an Element at the Tail
Slide 21
Slide 22
Slide 23
Slide 24
Deleting an Element at the Tail
Slide 26
Slide 27
Slide 28
Slide 29
Data Structure Exercises 5.1
Nội dung
Singly Linked Lists Definition: A linked list is a colleciton of nodes that together form a linear ordering. node : A compound object that stores a reference to an element and a reference, called next , to another node. Reference to another node Reference to an element next Element Node head next element next next next element element element Baltimore Rome Seattle Toronto link: The next reference inside a node is a link or pointer to another node. We can start from a given node, and move from it to the next and so on. This is called link hopping or pointer hopping . head next element next next next element element element Baltimore Rome Seattle Toronto head: The first node of a linked list tail: The last node of a linked list - it has a null next reference. head next element next next next element element element Baltimore Rome Seattle Toronto Such a linked list is called a singly linked list. tail pointer to a next node pointer to an element node Illustration of a linked list in memory: pointer to a next node pointer to an element node pointer to a next node pointer to an element node pointer to a next node pointer to an element node [...]... next element element Seattle next Toronto next element Baltimore should be removed How to insert a new node in the middle of a singly linked list? How to remove a node which in the middle of a singly linked list? Data Structure Exercises 5.1 Write a Java program to create a linked list as shown below head tail Φ …… 0 1 9 ... head = null; Node tail = null; Public Head_and_Tail linked_ list () { Node x = null; for (int i = 0; i < 10; i++) {x = new Node(); x.setElement(new Integer(i)); if (i == 0 ) {x.setNext(null); tail = x;} else x.setNext(head); head = x; } return new Head_and_Tail(head, tail);} } Deleting an Element at the Tail Deletion of an element at the tail of a singly linked list takes more effort The difficulty is related.. .Singly Linked Lists and Arrays Class Node Here is an implementation of nodes in Java: public class Node { private Object element; private Node next; public Node() { this( null, null ); } public Node( Object e, . Singly Linked Lists Definition: A linked list is a colleciton of nodes that together form a linear ordering of a linked list tail: The last node of a linked list - it has a null next reference. head next element next next next element element element Baltimore Rome Seattle Toronto Such a linked. Rome Seattle Toronto Such a linked list is called a singly linked list. tail pointer to a next node pointer to an element node Illustration of a linked list in memory: pointer to a next node pointer