Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.62 KB | None | 0 0
  1. private ListElement<T> findLastElement(){
  2.     if(this.firstElement == null)
  3.         return null; // nasza lista jest pusta
  4.     ListElement<T> currentElement = this.firstElement;
  5.     while(currentElement.hasNext()){
  6.         currentElement = currentElement.getNext();
  7.     }
  8.     return currentElement;
  9. }
  10.  
  11. public void add(T valueToAdd){
  12.     ListElement<T> newElement = new ListElement<T>(valueToAdd);
  13.     if(this.firstElement == null){ //dodajemy pierwszy element do listy
  14.         this.firstElement = newElement;
  15.     } else { //doczepiamy nowy elemeny na koniec listy
  16.         ListElement<T> lastElement = FindLastElement();
  17.         lastElement.setNext(lastElement);
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement