Linked List dan Double Linked List

Slides:



Advertisements
Presentasi serupa
Stack, Larik dan Pointer
Advertisements

Mata Kuliah : ALGORITMA dan STRUKTUR DATA 1.
Peta Kontrol (Untuk Data Variabel)
File Handling.
Menempatkan Pointer Q 6.3 & 7.3 NESTED LOOP.
Double Linked List.
Database Create-Retrieve-Update-Delete (CRUD)
Internal dan Eksternal Sorting
Sorting.
Single linked list.
Doubly Linked List Dr. Anto Satriyo Nugroho, M.Eng Web:
STRUKTUR DATA (7) single linked list circular
STRUKTUR DATA (8.1) double linked list non circular
LINKED LIST.
MODUL KULIAH STRUKTUR DATA TANGGAL REVISI TANGGAL BERLAKU KODE DOKUMEN :::::: September Session 8 Edited By Al-Bahra. L.B, S. Kom, M.
MEMORY Bhakti Yudho Suprapto,MT. berfungsi untuk memuat program dan juga sebagai tempat untuk menampung hasil proses bersifat volatile yang berarti bahwa.
Linked List BEBERAPA CONTOH SOAL 6.3 & 7.3 NESTED LOOP.
Pertemuan 2 STRUKTUR DATA LINKED LIST
Lecture 1 Introduction to C# Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
Mata Kuliah : Struktur Data Pertemuan : V
LINKED LIST Single Linked List.
LINKED LIST.
Linked List Pembuatan Simpul Awal.
Algoritma dan Struktur Data Daniel Riano Kaparang.
Lecture 8 Set and Dictionary Sandy Ardianto & Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
© 2009 Fakultas Teknologi Informasi Universitas Budi Luhur Jl. Ciledug Raya Petukangan Utara Jakarta Selatan Website:
Algoritma dan Struktur Data
Algoritma dan Struktur Data
Double Linked List. © 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Double Linked List Sama seperti single linked list, double.
Web Teknologi I (MKB511C) Minggu 12 Page 1 MINGGU 12 Web Teknologi I (MKB511C) Pokok Bahasan: – Text processing perl-compatible regular expression/PCRE.
Lecture 2 Introduction to C# - Object Oriented Sandy Ardianto & Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
MICROSOFT EXCEL 2000 Bagian #4 GRAPHICS : OBJECT & CHART.
Implementasi Binary Tree
Lecture 9 Single Linked List Sandy Ardianto & Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
STRUKTUR DATA (4) Array Stack(Tumpukkan) dan Queue (Antrian)
STRUKTUR DATA (6) single linked list non circular
Operasi pada pohon biner
Single Linked List Yuliana Setiowati, S.Kom.
BY YOHANA N Sumber Kepustakaan : yohananugraheni.files.wordpress.com/.../linked- lis... 1 LINKED LIST.
Algoritma & Struktur Data Linked List Evangs Mailoa.
LINKED LIST by Yohana N.
Struktur Data List Linear : Linked List (Double Linkedlist)
Linear Data Structures (Linked List). Node Link atau pointer data field.
Algoritma dan Struktur Data
Algoritma dan Struktur Data
Pertemuan ketujuh Struktur data st3telkom.ac.id
Tenia Wahyuningrum, S.Kom. MT
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
Pertemuan Linked list jual [Valdo] Lunatik Chubby Stylus.
Pertemuan 9 Stack dengan Linked-list
Binary Search Tree. Sebuah node di Binary Search Tree memiliki path yang unik dari root menurut aturan ordering – Sebuah Node, mempunyai subtree kiri.
Dynamic Array and Linked List
12. Doubly Linear Linked List
Matakuliah : T0534/Struktur Data Tahun : 2005 Versi : September 2005
11. Singly Circular Linked List
Linked List BEBERAPA CONTOH SOAL 6.3 & 7.3 NESTED LOOP.
Linked List INSERT KIRI 6.3 & 7.3 NESTED LOOP.
Linked List 6.3 & 7.3 NESTED LOOP.
Linked List INSERT KANAN 6.3 & 7.3 NESTED LOOP.
Linear Doubly INSERT KIRI
Algoritma dan Struktur Data
Algoritma dan Struktur Data
Linked List A group of data which is linked each other.
Conditional Move and Arrays
Transcript presentasi:

Linked List dan Double Linked List Kuliah 3 Struktur Data Linked List dan Double Linked List

Preliminaries Options for implementing an ADT List Array has a fixed size Data must be shifted during insertions and deletions Linked list is able to grow in size as needed Does not require the shifting of items during insertions and deletions © 2005 Pearson Addison-Wesley. All rights reserved

© 2005 Pearson Addison-Wesley. All rights reserved Pointers Figure 4.3 (a) declaring pointer variables; (b) pointing to statically allocating memory; (c) assigning a value; (d) allocating memory dynamically; (e) assigning a value © 2005 Pearson Addison-Wesley. All rights reserved

© 2005 Pearson Addison-Wesley. All rights reserved Pointers Figure 4.3 (f) copying a pointer; (g) allocating memory dynamically and assigning a value; (h) assigning NULL to a pointer variable; (i) deallocating memory © 2005 Pearson Addison-Wesley. All rights reserved

Pointer-Based Linked Lists Figure 4.7 A head pointer to a list Figure 4.8 A lost cell © 2005 Pearson Addison-Wesley. All rights reserved

Displaying the Contents of a Linked List Figure 4.9 The effect of the assignment cur = cur->next © 2005 Pearson Addison-Wesley. All rights reserved

Deleting a Specified Node from a Linked List Figure 4.10 Deleting a node from a linked list Figure 4.11 Deleting the first node © 2005 Pearson Addison-Wesley. All rights reserved

Inserting a Node into a Specified Position Figure 4.12 Inserting a new node into a linked list Figure 4.13 Inserting at the beginning of a linked list Figure 4.14 Inserting at the end of a linked list © 2005 Pearson Addison-Wesley. All rights reserved

LATIHAN

SOAL Buatlah fungsi untuk : melakukan pencarian berdasarkan key tertentu melakukan perhitungan berapa banyak data tertentu pada list tersebut melakukan penghapusan key tertentu dalam list melakukan penghapusan node di akhir list melakukan update terhadap nilai suatu node melakukan penambahan data dengan memperhatikan urutan

1. melakukan pencarian berdasarkan key tertentu int cari(int key,node *awal,node *akhir){ node *bantu; bantu = awal; while(bantu->data!=key && bantu!=NULL) { bantu=bantu->next; } if(bantu!=NULL) return 1; else return 0;

2. melakukan perhitungan berapa banyak data tertentu pada list tersebut int count(int key,node *awal,node *akhir){ node *bantu; int jumlah=0; bantu = awal; while(bantu!=NULL) { if(bantu->data==key) jumlah++; bantu=bantu->next; } return jumlah;

3. melakukan penghapusan key tertentu dalam list void hapusKey(int key,node *awal,node *akhir){ node *bantu, *hold; bantu = awal; while(bantu->next->data!=key && bantu!=NULL) { bantu=bantu->next; } if(bantu!=NULL) hold=bantu->next; bantu->next=hold->next; free(hold); else printf(“Data tidak ketemu”);

4. melakukan penghapusan node di akhir list void hapusKey(node *awal,node *akhir){ node *bantu; bantu = awal; while(bantu->next!=akhir) { bantu=bantu->next; } akhir=bantu; free(bantu->next); akhir->next=NULL;

5. melakukan update terhadap nilai suatu node void update(int baru, int lama,node *awal,node *akhir){ node *bantu; bantu = awal; while(bantu->data!=lama && bantu!=NULL) { bantu=bantu->next; } if(bantu!=NULL) bantu->data=baru;

void insertUrut(int dataBaru, node *awal, node *akhir){ node *baru,*bantu, *hold; baru=malloc(sizeof(node)); baru->data=dataBaru; if (awal==NULL){ awal=baru; akhir=baru; awal->next=NULL; } else { if(akhir->data<dataBaru) //call insertAkhir else if(awal->data>dataBaru) //call insertAwal else{ bantu=awal; while(bantu->next->data<dataBaru && bantu!=NULL) bantu=bantu->next; if(bantu!=NULL) { hold=bantu->next; bantu->next=baru; baru->next=hold; }}}}

© 2005 Pearson Addison-Wesley. All rights reserved Circular Linked Lists Last node references the first node Every node has a successor No node in a circular linked list contains NULL Figure 4.25 A circular linked list © 2005 Pearson Addison-Wesley. All rights reserved

© 2005 Pearson Addison-Wesley. All rights reserved Dummy Head Nodes Dummy head node Always present, even when the linked list is empty Insertion and deletion algorithms initialize prev to reference the dummy head node, rather than NULL Figure 4.27 A dummy head node © 2005 Pearson Addison-Wesley. All rights reserved

Doubly Linked Lists

Node data info: the user's data next, back: the address of the next and previous node in the list .back .info .next

Node data (cont.) template<class ItemType> struct NodeType { ItemType info; NodeType<ItemType>* next; NodeType<ItemType>* back; };

Finding a List Item We no longer need to use prevLocation (we can get the predecessor of a node using its back member)

Finding a List Item (cont.)

Inserting into a Doubly Linked List 1. newNode->back = location->back; 3. location->back->next=newNode; 2. newNode->next = location 4. location->back = newNode;

Deleting from a Doubly Linked List Be careful about the end cases!!

Doubly Linked Lists Figure 4.29 (a) A circular doubly linked list with a dummy head node (b) An empty list with a dummy head node © 2005 Pearson Addison-Wesley. All rights reserved

Summary Recursion can be used to perform operations on a linked list In a circular linked list, the last node points to the first node Dummy head nodes eliminate the special cases for insertion into and deletion from the beginning of a linked list © 2005 Pearson Addison-Wesley. All rights reserved