Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. public class Elem {
  2. private int number;
  3. private Elem next;
  4. Elem(int number){
  5. this.number = number;
  6. next = this;
  7. }
  8. public int getNumber(){
  9. return number;
  10. }
  11. public int checkLength() {
  12. int count = 1;
  13. Elem e = this;
  14. while (e.next != e){
  15. e = e.next;
  16. count++;
  17. }
  18. return count;
  19. }
  20. public void insertAfter(Elem x){
  21. if (x == this)
  22. throw new RuntimeException("The same element");
  23. Elem z = x.next;
  24. x.next = this.next;
  25. Elem k = this;
  26. while (k.next != k){
  27. k = k.next;
  28. }
  29. if (z != x)
  30. k.next = z;
  31. }
  32. public void deleteAfter(){
  33. if (this.next != this) {
  34. Elem z = this.next;
  35. this.next = z.next;
  36. z.next = null;
  37. }
  38. else throw new RuntimeException("Nothing after" + this);
  39. }
  40. public Elem findNumber(int x){
  41. Elem elem = this;
  42. if (elem.getNumber() == x){
  43. return elem;
  44. }
  45. while (elem != elem.next){
  46. elem = elem.next;
  47. if (elem.getNumber() == x)
  48. return elem;
  49. }
  50. return null;
  51. }
  52.  
  53. public String toString(){
  54. return "" + number + "" ;
  55. }
  56. }
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63. public class Test {
  64. public static void main(String [] args) {
  65. Vector a = new Vector(4);
  66. Vector b = new Vector(4);
  67. a.getVector(0,true);
  68. b.getVector(1,true);
  69. System.out.println(Vector.getSum(a,b));
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement