Guest User

Untitled

a guest
May 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Liste {
  4.  
  5. public ListenElement head, foot;
  6. public Liste() {
  7. head = foot = null;
  8. }
  9.  
  10. public void insert(int z){
  11. ListenElement wert = new ListenElement(z);
  12. wert.next = head;
  13. head = wert;
  14. if(foot == null){
  15. foot = wert;
  16. }
  17.  
  18. }
  19.  
  20. public void print(){
  21. System.out.print("Liste: [");
  22. print(head);
  23. System.out.println("]");
  24. }
  25.  
  26. public void print(ListenElement wert){
  27. if (wert == null) return;
  28. System.out.print(wert.zahl + "->");
  29. if (wert.next != null){
  30. System.out.print(" ");
  31. print(wert.next);
  32. }
  33. }
  34.  
  35.  
  36. public static void main (String ... Args){
  37. Liste a = new Liste();
  38. Random rand = new Random();
  39. for(int i=0; i<40; i++){
  40. int n = rand.nextInt(100);
  41. a.insert(n);
  42. }
  43. a.print();
  44.  
  45.  
  46. }
  47.  
  48. }
Add Comment
Please, Sign In to add comment