Linked List A group of data which is linked each other.

Slides:



Advertisements
Presentasi serupa
Double Linked List.
Advertisements

Single linked list.
STRUKTUR DATA (7) single linked list circular
STRUKTUR DATA (8.1) double linked list non circular
LINKED LIST.
LINKED LIST.
Pertemuan 2 STRUKTUR DATA LINKED LIST
Linked List dan Double Linked List
Struktur Data Queue Sandy dan Erick.
Mata Kuliah : Struktur Data Pertemuan : V
LINKED LIST Single Linked List.
LINKED LIST.
Implementasi Binary Tree
Lecture 9 Single Linked List Sandy Ardianto & Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
Queue.
STRUKTUR DATA (6) single linked list non circular
Algoritma & Struktur Data
Single Linked List Yuliana Setiowati, S.Kom.
Linear List Teknik Informatika Universitas Muhammadiyah Malang SP Algoritma & Struktur Data.
Algoritma & Struktur Data Linked List Evangs Mailoa.
Struktur Data List Linear : Linked List (Double Linkedlist)
Linear Data Structures (Linked List). Node Link atau pointer data field.
Algoritma dan Struktur Data
ADT Tree 2007/2008 – Ganjil – Minggu 8.
Implementasi ADT: Linked - List
Algoritma dan Struktur Data
Binary Search Tree 2007/2008 – Ganjil – Minggu 9.
Algoritma dan Struktur Data
Algoritma dan Struktur Data
Pertemuan ketujuh Struktur data st3telkom.ac.id
Tenia Wahyuningrum, S.Kom. MT
Linear List.
Struktur Data List Linear : Linked List (Single Linkedlist)
LINKED LIST.
Matakuliah : T0534/Struktur Data Tahun : 2005 Versi : September 2005
Struktur Data (Data Structure) – IS 2313
Pertemuan 7 stack jual [Valdo] Lunatik Chubby Stylus.
Algoritma dan Struktur Data
Algoritma dan Struktur Data
Algoritma dan Struktur Data
Pertemuan Linked list jual [Valdo] Lunatik Chubby Stylus.
Pertemuan 9 Stack dengan Linked-list
1 Pertemuan 4 Doubly Linked List Matakuliah: T0026/Struktur Data Tahun: 2005 Versi: 1/1.
Binary Search Tree. Sebuah node di Binary Search Tree memiliki path yang unik dari root menurut aturan ordering – Sebuah Node, mempunyai subtree kiri.
Double linked list non circular
STRUKTUR DATA (2) Single Linked List
STRUKTUR DATA Linked List Oleh : Yuli Praptomo PHS, S.Kom.
Binary Tree.
BAB3 QUEUE 6.3 & 7.3 NESTED LOOP.
8. Singly Linear Linked List
Single Linked List.
Dynamic Array and Linked List
12. Doubly Linear Linked List
Matakuliah : T0534/Struktur Data Tahun : 2005 Versi : September 2005
Fondasi Pemrograman & Struktur Data
Algoritma dan Struktur Data
Linear Data Structures (Array)
11. Singly Circular Linked List
Algoritma dan Struktur Data
Doubel Linked List.
STRUKTUR DATA (7) single linked list circular
Doubel Linked List.
DLL.
Single Linked List Circular (SLLC)
STRUKTUR DATA (8.2) double linked list circular
Double Linked List.
Algoritma dan Struktur Data
Algoritma dan Struktur Data
Algoritma dan Struktur Data
SINGLE LINKED LIST (SLL)
Transcript presentasi:

Linked List A group of data which is linked each other

Linked List via Array Linked List ADT Linked List Iteration ADT Ordered List ADT Sorted List ADT Double Linked List ADT Circular Linked List ADT

List Representation Via Array Difficult to organize a2a2 a1a1 unusedanan A n-1 A n-2 … a3a n-2 n-1 n m Size n

a2a2 a1a1 a9a9 A8A8 A7A7 a3a a4a4 a5a5 a6a6 a4a4 List Using Array a2a2 a1a1 a3a Insertion a4a4 a4a4 Insert(‘new’, 4) Shift right 1 position Position to insert a2a2 a1a1 a9a9 A8A8 A7A7 a3a a4a4 a5a5 a6a6 ‘new’a9a9 A8A8 A7A7 a6a6 a5a5

a2a2 a1a1 a9a9 a8a8 a7a7 a3a a4a4 a5a5 a6a6 ‘new’ List Using Array Deletion delete(7) Shift left 1 position Position to delete a2a2 a1a1 a9a9 a8a8 a7a7 a3a a4a4 a5a5 ‘new’a2a2 a1a1 a9a9 a8a8 a7a7 a3a a4a4 a5a5 a6a6 ‘new’

Linked-list Insertion/deletion is slow cause it has to shift items in contiguous memory HIGH COST Items is not need to be contiguous

List Node a Element next class ListNode{ Object element; ListNode next; ListNode(Object obj) { element = obj; next = null; } ListNode(Object obj, ListNode node) { element = obj; next = node; }

List Node a1a1 a2a2 a3a3 head a4a4 null ListNode node4 = new ListNode(a4);// new ListNode(a4, null); ListNode node3 = new ListNode(a3, node4); ListNode node2 = new ListNode(a2, node3); ListNode head = new ListNode(a1, node2);

Linked-List Linked-List ADT a1a1 a2a2 a3a3 head a4a4 null LinkedList() addHead(obj) isEmpty() deleteHead() retrieveHead() getHead()

Linked-List list Linked-List LinkedList list = new LinkedList(); list.add(a4); list.add(a3);// list.insert(a3,a4); list.add(a2); // list.insert (a2,a3); list.add(a1); a1a1 a2a2 a3a3 head a4a4 LinkedList()

Linked-List Inserting Node a1a1 a2a2 a3a3 a4a4 head current X obj temp

Linked-List Inserting Node We need a help to point node before inserted node (say it ‘current’) Inserted node is named newNode a1a1 a2a2 a4a4 head current X obj newNode public void insertNext (Object obj) { ListNode newNode; if (current != null) { newNode = new ListNode(obj, current.next); current.next = newNode; } else if (zeroflag) head = new ListNode(obj,head); else {throw new ItemNotFound(“insert fails”)} }

Linked-List Deleting Node We need a help to point node before deleted node (say it ‘current’) Deleted node is node after current a1a1 a2a2 a4a4 head current public void deleteNext (Object obj) { current = head; while (current.element != obj && current.next != null) current = current.next; if (current.next != null) { ListNode temp = current.next;// code in C++ current.next = current.next.next; release(temp); // code in C++ } else {throw new ItemNotFound(“delete fails”)} } a3a3 X temp

Linked-List Linked-List Iteration ADT LinkedListItr() zeroth() retrieve() deleteNext() isLast() isInList() first() advance() insertNext(obj) Linked-ListItr current a1a1 a2a2 a3a3 head a4a4 null acces and change nodes acces and change current pointer

Linked-List Inserting Node in Linked List Iteration We have had current that points to a node before inserted position Node is inserted after current position Inserted node is named newNode a1a1 a2a2 a4a4 head current X obj newNode public void insertNext (Object obj) { ListNode newNode; if (isInList()) { newNode = new ListNode(obj, current.next); current.next = newNode; } else if (zeroflag) head = new ListNode(obj,head); else {throw new ItemNotFound(“insert fails”)} }

Linked-List Deleting Node in Linked List Iteration Deleted node is node after current a1a1 a2a2 a4a4 head current public void deleteNext () { current = head; while (current.element != obj && current.next != null) current = current.next; if (current.next != null) { ListNode temp = current.next;// code in C++ current.next = current.next.next; release(temp); // code in C++ } else {throw new ItemNotFound(“delete fails”)} } a3a3 X temp

Retrieve Next Element in Linked List Iteration Linked-List public int retrieveNext() { if (current.next() <>null)//if(isInList()) return current.next.element; else return null; }

OrderedList Ordered List ADT list OrderedList () insert (obj, index) delete(index) retrieve (index) length() Linked-List Iteration ADT

Ordered List Implementation Linked-List class OrderedList ( private LinkedListItr list; private int pos=0; public OrderedList() {list=new LinkedListItr ();} public int length() { int count=0; for (list.first(); list.isInList(); list.advance()) {count++;} return count; } public int retrieve(int i) { if (this.setPos(i)) return list.retrieve(); else return null; } private setPos(int i) { if (pos>i) {list.first(); pos=0;} for (int i=i-pos; list.isInList(); list.advance()) { pos++; } public advance() { if (! list.isLast()) { list.advance(); pos++; }

OrderedList Sorted List ADT list SortedList () insert (obj) delete(index) retrieve (index) length() Linked-List Iteration ADT