widness
1/17/2018 - 4:17 PM

waitingList_basic

A basic waiting list class

public class Input {
  private int information;
	private Input next;
	
	// Konstruktor
	public Telefonat (int nummer, String sprache, int telnr) {
		this.nummer = nummer;
		this.sprache = sprache;
		this.telefonnummer = telnr;
		next = null;
	}
public class WaitingList {
	private Input first;
	private Input last;
	
	public WaitingList () {
		first = last = null;
	}

	// einfügen am Beginn
	public void insert (Input newInput) {
		if (first == null) {// erstes Element
			first = last = newInput;
		}
		else { // vorne einfügen
			newInput.setNext(first);
			first = newInput;
		}
	}
	
	// entfernen am Schluss
	public Input remove () {
		Input tel = last;
		Input prev = first;
		
		if (tel != null) {
			if (first == last) // letztes Element wird entfernt
				first = last = null;
			else {
				while (prev.getNext() != last) // Vorgänger suchen
					prev = prev.getNext();
				
				last = prev;
				prev.setNext(null);
			}
		}

		return tel;
	}
}