Docsity

Implementasi linked list, Study notes of Algorithms and Programming

Partial preview of the text

Download Implementasi linked list and more Study notes Algorithms and Programming in PDF only on Docsity!

IMPLEMENTASI LINKED LIST

IMPLEMENTASI LINKED LIST 1. package Pertemuan4LinkedList; 2. 3. import java.util.LinkedList; A. 5. public class ContohSenarai { 6. 7. public static void main(String[] args) { 8. LinkedList senarai = new LinkedList(); 9. Simpul simpul; 16. 11. //Masukkan 5 nama 12. senarai.push(new Simpul("AMN", “Aminudin")); 13. senarai.push(new Simpul("ZAS", “Zaskia")); 14. senarai.push(new Simpul("RIN", “Rina Melati")); 15. senarai.push(new Simpul("FAR", “Farhan™)); 16. senarai.push(new Simpul(“AGN", “Agnes Monica")); 17. 18. System.out.printIn("Keadaan awal"); 19. for (int i = @; i < senarai.size(); i++) { 28. simpul = senarai.get(i); 21. simpul.display(); 22. } 23. 24. hapus(senarai, “RIN"); 25. 26. System.out.printin(); 27. System.out.printin("Setelah RIN dihapus"); 28. for (int i = @; i < senarai-size(); i++) { 29. simpul = senarai.get(i); 38. simpul.display(); 31. }