Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. package listapp;
  2. public class Node {
  3. private int Data;
  4. private Integer NextAddress;
  5. public Node(int InputData)
  6. {
  7. Data = InputData;
  8. NextAddress = null;
  9. }
  10. public void SetData(int InputData)
  11. {
  12. Data = InputData;
  13. }
  14. public void SetNextAddress(int InputNextAddress)
  15. {
  16. NextAddress = InputNextAddress;
  17. }
  18. public int GetData(){
  19. return Data;
  20. }
  21. public Integer GetNextAddress()
  22. {
  23. return NextAddress;
  24. }
  25.  
  26. }
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34. package listapp;
  35.  
  36. public class ListApp {
  37.  
  38. public static void main(String[] args) {
  39. LinkedList x = new LinkedList(100);
  40. x.AddNodeAtEnd(10);
  41. x.AddNodeAtEnd(20);
  42. x.AddNodeAtEnd(30);
  43. System.out.println("");
  44. }
  45.  
  46. }
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57. package listapp;
  58.  
  59. public class LinkedList {
  60.  
  61. Node[] LL;
  62. int CurrentIndex = 0;
  63.  
  64. public LinkedList(int Size)
  65. {
  66. LL = new Node[Size];
  67. }
  68.  
  69. public void AddNodeAtEnd(int Data)
  70. {
  71. Node temp = new Node(Data);
  72. if(CurrentIndex > 0){
  73. LL[CurrentIndex - 1].SetNextAddress(CurrentIndex);
  74. }
  75. LL[CurrentIndex] = temp;
  76. CurrentIndex++;
  77. }
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement