Jika kita ingin insert data setelah NODE tertentu, berikut adalah fungsinya:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | void insertBeforeNode(int databaru) { int x, y; NodBaru(databaru); if(isEmpty() == 1) { head = baru; tail = baru; } else { int count = 0; bantu = head; while(bantu != NULL) { bantu = bantu->next; count++; |
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | cout << "Mau insert sebelum NODE ke berapa : "; cin >> x; if(x > count) { cout << "\nMaaf data tidak bisa masuk, overflow!\n"; tampil(); } else { bantu = head; if(x == 1) { baru->next = head; head = baru; } else { y = 1; while(y < x-1) { bantu = bantu->next; y++; } baru->next = bantu->next; bantu->next = baru; } cout << "\n----- Data masuk ------\n"; } } } |
2 komentar:
:? :?
vebri
:~
Posting Komentar