Presentation is loading. Please wait.

Presentation is loading. Please wait.

Double Linked List Entin Martiana. Operasi Double Linked List Membangun Double Linked List dalam dua arah.Membaca list, dalam dua arah. Mencari simpul.

Similar presentations


Presentation on theme: "Double Linked List Entin Martiana. Operasi Double Linked List Membangun Double Linked List dalam dua arah.Membaca list, dalam dua arah. Mencari simpul."— Presentation transcript:

1 Double Linked List Entin Martiana

2 Operasi Double Linked List Membangun Double Linked List dalam dua arah.Membaca list, dalam dua arah. Mencari simpul tertentu Menghapus simpul tertentu Menyisipkan sebagai simpul pertama Menyisipkan simpul di tengah

3 Double Linked List head tail

4 Deklarasi struct simpul { char nama[25]; int nrp; struct simpul *before; struct simpul *next; }; struct simpul *baru; nama nrp before simpul data pointer yg menunjuk simpul sebelumnya next pointer yg menunjuk simpul berikutnya

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

6 Bagaimana? 1.struct simpul *baru; 2.baru=(struct simpul*)malloc(sizeof(struct simpul)); 3.printf("Nama:");scanf("%s",&baru->nama); 4.printf("NRP:");scanf("%d",&baru->nrp); 5.if(pertama) { baru->before=NULL; nama1 nrp1 before baru nama1 nrp1 before baru next NULL

7 Bagaimana? 1.struct simpul *baru; 2.baru=(struct simpul*)malloc(sizeof(struct simpul)); 3.printf("Nama:");scanf("%s",&baru->nama); 4.printf("NRP:");scanf("%d",&baru->nrp); 5.if(pertama) { baru->before=NULL; baru->next=NULL; nama1 nrp1 before NULL baru nama1 nrp1 before baru next NULL

8 Bagaimana? 1.struct simpul *baru; 2.baru=(struct simpul*)malloc(sizeof(struct simpul)); 3.printf("Nama:");scanf("%s",&baru->nama); 4.printf("NRP:");scanf("%d",&baru->nrp); 5.if(pertama) { baru->before=NULL; baru->next=NULL; head=baru; nama1 nrp1 before NULL head nama1 nrp1 before baru next NULL baru

9 Bagaimana? 1.struct simpul *baru; 2.baru=(struct simpul*)malloc(sizeof(struct simpul)); 3.printf("Nama:");scanf("%s",&baru->nama); 4.printf("NRP:");scanf("%d",&baru->nrp); 5.if(pertama) { baru->before=NULL; baru->next=NULL; head = baru; tail = baru; } nama1 nrp1 before NULL head nama1 nrp1 before baru next NULL baru tail

10 Selanjutnya 1.baru=(struct simpul*)malloc(sizeof(struct simpul)); 2.printf("Nama:");scanf("%s",&baru->nama); 3.printf("NRP:");scanf("%d",&baru->nrp); 4.if(bukanpertama) { baru->next=NULL; nama2 nrp2 before NULL baru nama1 nrp1 before head nama2 nrp2 before baru next NULL tail

11 Selanjutnya 1.baru=(struct simpul*)malloc(sizeof(struct simpul)); 2.printf("Nama:");scanf("%s",&baru->nama); 3.printf("NRP:");scanf("%d",&baru->nrp); 4.if(bukanpertama) { baru->next=NULL; tail->next=baru; nama2 nrp2 before NULL baru nama1 nrp1 before head nama2 nrp2 before baru next NULL tail

12 Selanjutnya 1.baru=(struct simpul*)malloc(sizeof(struct simpul)); 2.printf("Nama:");scanf("%s",&baru->nama); 3.printf("NRP:");scanf("%d",&baru->nrp); 4.if(bukanpertama) { baru->next=NULL; tail->next=baru; baru->before=tail; nama2 nrp2 before NULL baru nama1 nrp1 before head nama2 nrp2 before baru next NULL tail

13 Selanjutnya 1.baru=(struct simpul*)malloc(sizeof(struct simpul)); 2.printf("Nama:");scanf("%s",&baru->nama); 3.printf("NRP:");scanf("%d",&baru->nrp); 4.if(j<>0) { baru->next=NULL; tail->next=baru; baru->before=tail; tail=baru; } nama2 nrp2 before NULL tail nama1 nrp1 before head nama2 nrp2 before baru next NULL

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

15 Membaca (FIFO) nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL bacaFIFO = head; bacaFIFO

16 Membaca (FIFO) nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL while (bacaFIFO!=NULL) // fungsi menampilkan bacaFIFO = bacaFIFO -> next; bacaFIFO

17 Membaca (FIFO) nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL while (bacaFIFO!=NULL) // fungsi menampilkan bacaFIFO = bacaFIFO -> next; bacaFIFO

18 Membaca (FIFO) nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL while (bacaFIFO!=NULL) // fungsi menampilkan bacaFIFO = bacaFIFO -> next; bacaFIFO

19 Membaca (FIFO) nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL while (bacaFIFO<>NULL) // fungsi menampilkan bacaFIFO = bacaFIFO -> next; bacaFIFO

20 Membaca (LIFO) nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL bacaLIFO = tail; bacaLIFO

21 Membaca (LIFO) nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL while (bacaLIFO<>NULL) // fungsi menampilkan bacaLIFO = bacaLIFO -> before; bacaLIFO

22 Membaca (LIFO) nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL while (bacaLIFO<>NULL) // fungsi menampilkan bacaLIFO = bacaLIFO -> before; bacaLIFO

23 Membaca (LIFO) nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL while (bacaLIFO<>NULL) // fungsi menampilkan bacaLIFO = bacaLIFO -> before; bacaLIFO

24 Membaca (LIFO) nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL while (bacaLIFO<>NULL) // fungsi menampilkan bacaLIFO = bacaLIFO -> before; bacaLIFO

25 Mencari Simpul Tertentu nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL cari = head; cari

26 Mencari Simpul Tertentu nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL while (cari->nama!=nama3) cari = cari -> next; cari

27 Mencari Simpul Tertentu nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL while (cari->nama!=nama3) cari = cari -> next; cari

28 Mencari Simpul Tertentu nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL while (cari->nama!=nama3) cari = cari -> next; cari

29 Menghapus Simpul Tertentu (Simpul Depan) nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL cari = head; cari

30 Menghapus Simpul Tertentu (Simpul Depan) nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL cari = head; if(cari->nama==nama1) head=head->next; cari

31 Menghapus Simpul Tertentu (Simpul Depan) nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL cari = head; if(cari->nama==nama) head=head->next; head->before=NULL; cari NULL

32 Menghapus Simpul Tertentu (Simpul Depan) nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL cari = head; if(cari->nama==nama) head=head->next; head->before=NULL; free(cari); cari NULL

33 Menghapus Simpul Tertentu (Simpul Depan) nama4 nrp4 before NULL tail head next nama2 nrp2 before next nama3 nrp3 before next cari = head; if(cari->nama==nama) head=head->next; head->before=NULL; free(cari); NULL

34 Menghapus Simpul Tertentu (Simpul Akhir) nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL cari=tail; cari

35 Menghapus Simpul Tertentu (Simpul Akhir) nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL tail=tail->before; cari

36 Menghapus Simpul Tertentu (Simpul Akhir) nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL tail=tail->before; tail->next=NULL; cari

37 Menghapus Simpul Tertentu (Simpul Akhir) nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL tail=tail->before; tail->next=NULL; free(cari); cari

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

39 Menghapus Simpul Tertentu (Di Tengah) nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL cari=head; cari

40 Menghapus Simpul Tertentu (Di Tengah) nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL while (cari->nama!=nama3) cari = cari -> next; cari

41 Menghapus Simpul Tertentu (Di Tengah) nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL while (cari->nama!=nama3) cari = cari -> next; cari

42 Menghapus Simpul Tertentu (Di Tengah) nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL while (cari->nama!=nama3) cari = cari -> next; cari

43 Menghapus Simpul Tertentu (Di Tengah) nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL cari->before->next=cari->next; cari

44 Menghapus Simpul Tertentu (Di Tengah) nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL cari->next->before=cari->before; cari

45 Menghapus Simpul Tertentu (Di Tengah) nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL free(cari); cari

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

47 atau nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL while (cari->nama!=nama3) cari = cari -> next; sbl=cari->before; stl=cari->next; cari sbl stl

48 Menghapus Simpul Tertentu nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL sbl->next=stl; cari sbl stl

49 Menghapus Simpul Tertentu nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL sbl->next=stl; stl->before=sbl; cari sbl stl

50 Menghapus Simpul Tertentu nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next NULL cari->before->next = cari->next; cari->next->before = cari->before; free(cari);

51 Menyisipkan sebagai simpul pertama nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL namax nrpx before sisip next

52 Menyisipkan sebagai simpul pertama nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL namax nrpx before sisip next sisip->before=NULL; NULL

53 Menyisipkan sebagai simpul pertama nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL namax nrpx before sisip next sisip->next=head; NULL

54 Menyisipkan sebagai simpul pertama nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next namax nrpx before sisip next head->before=sisip; NULL

55 Menyisipkan sebagai simpul pertama nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next namax nrpx before sisip next head=sisip; NULL

56 Menyisipkan stl. simpul tertentu nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL namax nrpx before sisip next

57 Menyisipkan stl. simpul tertentu nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL namax nrpx before sisip next stl=head; while(stl->nama!=nama3) stl=stl->next; stl

58 Menyisipkan stl. simpul tertentu nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL namax nrpx before sisip next sisip->before=stl; stl

59 Menyisipkan stl. simpul tertentu nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL namax nrpx before sisip next sisip->before=stl; sisip->next=stl->next; stl

60 Menyisipkan stl. simpul tertentu nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL namax nrpx before sisip next sisip->before=stl; sisip->next=stl->next; stl->next->before=sisip; stl

61 Menyisipkan stl. simpul tertentu nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL namax nrpx before sisip next sisip->before=stl; sisip->next=stl->next; stl->next->before=sisip; stl->next=sisip; stl

62 Menyisipkan sbl. simpul tertentu nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL namax nrpx before sisip next

63 Menyisipkan sbl. simpul tertentu nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL namax nrpx before sisip next sbl=head; while(sbl->nama!=nama3) sbl=sbl->next; sbl

64 Menyisipkan sbl. simpul tertentu nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL namax nrpx before sisip next sisip->next=sbl; sbl

65 Menyisipkan sbl. simpul tertentu nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL namax nrpx before sisip next sisip->next=sbl; sisip->before=sbl->before; sbl

66 Menyisipkan sbl. simpul tertentu nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL namax nrpx before sisip next sisip->next=sbl; sisip->before=sbl->before; sbl->before->next=sisip; sbl

67 Menyisipkan sbl. simpul tertentu nama4 nrp4 before NULL tail nama1 nrp1 before head next nama2 nrp2 before next nama3 nrp3 before next NULL namax nrpx before sisip next sisip->next=sbl; sisip->before=sbl->before; sbl->before->next=sisip; sbl->before=sisip; sbl


Download ppt "Double Linked List Entin Martiana. Operasi Double Linked List Membangun Double Linked List dalam dua arah.Membaca list, dalam dua arah. Mencari simpul."

Similar presentations


Ads by Google