Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. public class Node {
  2. private int inf;
  3. private Node next;
  4.  
  5. Node() {
  6. inf=0;
  7. next=null;
  8. }
  9. Node(int i) {
  10. inf=i;
  11. next=null;
  12. }
  13.  
  14. public void setInf(int i) {
  15. inf=i;
  16. }
  17. public void setNext(Node n) {
  18. next=n;
  19. }
  20.  
  21. public int getInf() {
  22. return inf;
  23. }
  24. public Node getNext() {
  25. return next;
  26. }
  27. }
  28.  
  29. public class List {
  30. private Node first;
  31. List() {
  32. first=null;
  33. }
  34.  
  35. public void addFirstNode(Node n) {
  36. n.setNext(first);
  37. first=n;
  38. }
  39.  
  40. public void addLastNode(Node n) {
  41. if (first==null) first=n;
  42. else {
  43. Node tmp=first;
  44. while (tmp.getNext()!=null) {
  45. tmp=tmp.getNext();
  46. }
  47.  
  48. tmp.setNext(n);
  49. }
  50. }
  51. public void addFirst(int a) {
  52. Node newnode = new Node(a);
  53. addFirstNode(newnode);
  54. }
  55.  
  56. public void addLast(int a) {
  57. Node newnode = new Node(a);
  58. addLastNode(newnode);
  59. }
  60.  
  61. public void showList() {
  62. Node tmp=first;
  63. while (tmp!=null) {
  64. System.out.print(" "+tmp.getInf());
  65. tmp=tmp.getNext();
  66. }
  67. System.out.println();
  68. }
  69.  
  70. }
  71.  
  72. package dom;
  73.  
  74. //основная программа
  75.  
  76. public class Dom {
  77.  
  78. public static void main(String[] args) {
  79. List queue = new List();
  80. List stack = new List();
  81.  
  82. String s = "125478965321547896521547889633215478965487512546985478521";
  83.  
  84. int l = s.length();
  85. for (int i=0; i<l; i++) {
  86. if (i%2==0)
  87. { char k=s.charAt(i);
  88. queue.addLast(k);
  89. }
  90. if (i%5==0)
  91. { char k=s.charAt(i);
  92. stack.addFirst(k);
  93. }
  94. }
  95.  
  96. queue.showList();
  97. stack.showList();
  98. }
  99. }
  100.  
  101. System.out.print(" " + (char)tmp.getInf());
  102.  
  103. public void showList() {
  104. Node tmp=first;
  105. while (tmp!=null) {
  106. System.out.print(" "+ (char)tmp.getInf()); //здесь преобразование кода в символ
  107. tmp=tmp.getNext();
  108. }
  109. System.out.println();
  110. }
  111.  
  112. //Node
  113. private Object inf;
  114. Node(Object inf){
  115. this.inf = inf;
  116. next = null;
  117. }
  118. public void setInf(Object inf){
  119. this.inf = inf;
  120. }
  121. public Object getInf(){
  122. return inf;
  123. }
  124.  
  125. //List
  126. public void addFirst(Object inf){
  127. Node newnode = new Node(inf);
  128. addFirstNode(newnode);
  129. }
  130. public void addLast(Object inf){
  131. Node newnode = new Node(inf);
  132. addLastNode(newnode);
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement