1 / 67

Double Linked List

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.

gita
Download Presentation

Double Linked List

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Double Linked List Entin Martiana

  2. 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

  3. Double Linked List 0 1 2 3 4 tail head

  4. 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

  5. Membangun Linked List Apa yang harus dilakukan? • Deklarasi • Memory allocation • Mengisi data • Menyiapkan untuk dihubungkan dengan data baru berikutnya

  6. 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

  7. 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

  8. 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

  9. 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

  10. 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

  11. 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

  12. 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

  13. 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

  14. Sampai iterasi keempat tail head nama3 nrp3 nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before before next next next next NULL NULL

  15. 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;

  16. 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;

  17. 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;

  18. 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;

  19. 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;

  20. 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;

  21. 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;

  22. 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;

  23. 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;

  24. 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;

  25. 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;

  26. 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;

  27. 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;

  28. 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;

  29. 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;

  30. 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;

  31. 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;

  32. 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);

  33. 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);

  34. 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;

  35. 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;

  36. 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;

  37. 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);

  38. Menghapus Simpul Tertentu (Simpul Akhir) head tail nama3 nrp3 nama2 nrp2 nama1 nrp1 before before before next next next NULL NULL

  39. 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;

  40. 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;

  41. 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;

  42. 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;

  43. 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;

  44. 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;

  45. 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);

  46. Menghapus Simpul Tertentu (Di Tengah) head tail nama2 nrp2 nama1 nrp1 nama4 nrp4 before before before next next next NULL NULL

  47. 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;

  48. 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;

  49. 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;

  50. 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);

More Related