690 likes | 937 Views
Double Linked List. Entin Martiana. Operasi Double Linked List. Membangun Double Linked List Membaca list, dalam dua arah. Mencari simpul tertentu Menghapus simpul tertentu Menyisipkan sebagai simpul pertama Menyisipkan simpul di tengah. Double Linked List. 0. 1. 2. 3. 4. tail.
E N D
Double Linked List Entin Martiana
Operasi Double Linked List • Membangun Double Linked List • Membaca list, dalam dua arah. • Mencari simpul tertentu • Menghapus simpul tertentu • Menyisipkan sebagai simpul pertama • Menyisipkan simpul di tengah
Double Linked List 0 1 2 3 4 tail head
Deklarasi struct simpul { char nama[25]; int nrp; struct simpul *before; struct simpul *next; }; struct simpul *baru; simpul nama nrp data pointer yg menunjuk simpul sebelumnya before pointer yg menunjuk simpul berikutnya next
Membangun Linked List Apa yang harus dilakukan? • Deklarasi • Memory allocation • Mengisi data • Menyiapkan untuk dihubungkan dengan data baru berikutnya
Bagaimana? baru • struct simpul *baru; • baru=(struct simpul*)malloc(sizeof(struct simpul)); • printf("Nama :");scanf("%s",&baru->nama); • printf("NRP :");scanf("%d",&baru->nrp); • if(pertama) { baru->before=NULL; nama1 nrp1 before next baru nama1 nrp1 before NULL next
Bagaimana? baru • struct simpul *baru; • baru=(struct simpul*)malloc(sizeof(struct simpul)); • printf("Nama :");scanf("%s",&baru->nama); • printf("NRP :");scanf("%d",&baru->nrp); • if(pertama) { baru->before=NULL; baru->next=NULL; nama1 nrp1 before next baru nama1 nrp1 before NULL next NULL
Bagaimana? baru • struct simpul *baru; • baru=(struct simpul*)malloc(sizeof(struct simpul)); • printf("Nama :");scanf("%s",&baru->nama); • printf("NRP :");scanf("%d",&baru->nrp); • if(pertama) { baru->before=NULL; baru->next=NULL; head=baru; nama1 nrp1 before next head baru nama1 nrp1 before NULL next NULL
Bagaimana? baru • struct simpul *baru; • baru=(struct simpul*)malloc(sizeof(struct simpul)); • printf("Nama :");scanf("%s",&baru->nama); • printf("NRP :");scanf("%d",&baru->nrp); • if(pertama) { baru->before=NULL; baru->next=NULL; head = baru; tail = baru; } nama1 nrp1 before next head baru tail nama1 nrp1 before NULL next NULL
Selanjutnya baru • baru=(struct simpul*)malloc(sizeof(struct simpul)); • printf("Nama :");scanf("%s",&baru->nama); • printf("NRP :");scanf("%d",&baru->nrp); • if(bukanpertama) { baru->next=NULL; nama2 nrp2 before next baru tail head nama1 nrp1 nama2 nrp2 before before NULL next next NULL NULL
Selanjutnya baru • baru=(struct simpul*)malloc(sizeof(struct simpul)); • printf("Nama :");scanf("%s",&baru->nama); • printf("NRP :");scanf("%d",&baru->nrp); • if(bukanpertama) { baru->next=NULL; tail->next=baru; nama2 nrp2 before next baru tail head nama1 nrp1 nama2 nrp2 before before NULL next next NULL
Selanjutnya baru • baru=(struct simpul*)malloc(sizeof(struct simpul)); • printf("Nama :");scanf("%s",&baru->nama); • printf("NRP :");scanf("%d",&baru->nrp); • if(bukanpertama) { baru->next=NULL; tail->next=baru; baru->before=tail; nama2 nrp2 before next baru tail head nama1 nrp1 nama2 nrp2 before before NULL next next NULL
Selanjutnya baru • baru=(struct simpul*)malloc(sizeof(struct simpul)); • printf("Nama :");scanf("%s",&baru->nama); • printf("NRP :");scanf("%d",&baru->nrp); • if(j<>0) { baru->next=NULL; tail->next=baru; baru->before=tail; tail=baru; } nama2 nrp2 before next tail head nama1 nrp1 nama2 nrp2 before before NULL next next NULL
Sampai iterasi keempat tail head nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL
Membaca (FIFO) head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL bacaFIFO bacaFIFO = head;
Membaca (FIFO) head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL bacaFIFO while (bacaFIFO!=NULL) // fungsi menampilkan bacaFIFO = bacaFIFO -> next;
Membaca (FIFO) head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL bacaFIFO while (bacaFIFO!=NULL) // fungsi menampilkan bacaFIFO = bacaFIFO -> next;
Membaca (FIFO) head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL bacaFIFO while (bacaFIFO!=NULL) // fungsi menampilkan bacaFIFO = bacaFIFO -> next;
Membaca (FIFO) head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL bacaFIFO while (bacaFIFO<>NULL) // fungsi menampilkan bacaFIFO = bacaFIFO -> next;
Membaca (LIFO) head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL bacaLIFO bacaLIFO = tail;
Membaca (LIFO) head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL bacaLIFO while (bacaLIFO<>NULL) // fungsi menampilkan bacaLIFO = bacaLIFO -> before;
Membaca (LIFO) head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL bacaLIFO while (bacaLIFO<>NULL) // fungsi menampilkan bacaLIFO = bacaLIFO -> before;
Membaca (LIFO) head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL bacaLIFO while (bacaLIFO<>NULL) // fungsi menampilkan bacaLIFO = bacaLIFO -> before;
Membaca (LIFO) head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL bacaLIFO while (bacaLIFO<>NULL) // fungsi menampilkan bacaLIFO = bacaLIFO -> before;
Mencari Simpul Tertentu head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL cari cari = head;
Mencari Simpul Tertentu head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL cari while (cari->nama!=nama3) cari = cari -> next;
Mencari Simpul Tertentu head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL cari while (cari->nama!=nama3) cari = cari -> next;
Mencari Simpul Tertentu head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL cari while (cari->nama!=nama3) cari = cari -> next;
Menghapus Simpul Tertentu (Simpul Depan) head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL cari cari = head;
Menghapus Simpul Tertentu (Simpul Depan) head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL cari cari = head; if(cari->nama==nama1) head=head->next;
Menghapus Simpul Tertentu (Simpul Depan) head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL NULL cari cari = head; if(cari->nama==nama) head=head->next; head->before=NULL;
Menghapus Simpul Tertentu (Simpul Depan) head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL NULL cari cari = head; if(cari->nama==nama) head=head->next; head->before=NULL; free(cari);
Menghapus Simpul Tertentu (Simpul Depan) head tail nama3 nrp3 nama2 nrp2 nama4 nrp4 before before before next next next NULL NULL cari = head; if(cari->nama==nama) head=head->next; head->before=NULL; free(cari);
Menghapus Simpul Tertentu (Simpul Akhir) head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL cari cari=tail;
Menghapus Simpul Tertentu (Simpul Akhir) head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL cari tail=tail->before;
Menghapus Simpul Tertentu (Simpul Akhir) head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL cari tail=tail->before; tail->next=NULL;
Menghapus Simpul Tertentu (Simpul Akhir) head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL cari tail=tail->before; tail->next=NULL; free(cari);
Menghapus Simpul Tertentu (Simpul Akhir) head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 before before before next next next NULL NULL
Menghapus Simpul Tertentu (Di Tengah) head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL cari cari=head;
Menghapus Simpul Tertentu (Di Tengah) head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL cari while (cari->nama!=nama3) cari = cari -> next;
Menghapus Simpul Tertentu (Di Tengah) head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL cari while (cari->nama!=nama3) cari = cari -> next;
Menghapus Simpul Tertentu (Di Tengah) head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL cari while (cari->nama!=nama3) cari = cari -> next;
Menghapus Simpul Tertentu (Di Tengah) head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL cari cari->before->next=cari->next;
Menghapus Simpul Tertentu (Di Tengah) head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL cari cari->next->before=cari->before;
Menghapus Simpul Tertentu (Di Tengah) head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL cari free(cari);
Menghapus Simpul Tertentu (Di Tengah) head tail nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before next next next NULL NULL
atau head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL stl sbl cari while (cari->nama!=nama3) cari = cari -> next; sbl=cari->before; stl=cari->next;
Menghapus Simpul Tertentu head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL sbl stl cari sbl->next=stl;
Menghapus Simpul Tertentu head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL stl sbl cari sbl->next=stl; stl->before=sbl;
Menghapus Simpul Tertentu head tail nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before next next next NULL NULL cari->before->next = cari->next; cari->next->before = cari->before; free(cari);