Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Elem {
- private int number;
- private Elem next;
- Elem(int number){
- this.number = number;
- next = this;
- }
- public int getNumber(){
- return number;
- }
- public int checkLength() {
- int count = 1;
- Elem e = this;
- while (e.next != e){
- e = e.next;
- count++;
- }
- return count;
- }
- public void insertAfter(Elem x){
- if (x == this)
- throw new RuntimeException("The same element");
- Elem z = x.next;
- x.next = this.next;
- Elem k = this;
- while (k.next != k){
- k = k.next;
- }
- if (z != x)
- k.next = z;
- }
- public void deleteAfter(){
- if (this.next != this) {
- Elem z = this.next;
- this.next = z.next;
- z.next = null;
- }
- else throw new RuntimeException("Nothing after" + this);
- }
- public Elem findNumber(int x){
- Elem elem = this;
- if (elem.getNumber() == x){
- return elem;
- }
- while (elem != elem.next){
- elem = elem.next;
- if (elem.getNumber() == x)
- return elem;
- }
- return null;
- }
- public String toString(){
- return "" + number + "" ;
- }
- }
- public class Test {
- public static void main(String [] args) {
- Vector a = new Vector(4);
- Vector b = new Vector(4);
- a.getVector(0,true);
- b.getVector(1,true);
- System.out.println(Vector.getSum(a,b));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement