Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class WaitingList
- {
- private int numNodes;
- private ListNode front;
- public WaitingList(){
- front = null;
- numNodes = 0;
- }
- public int size()
- {return numNodes;}
- public void add(Object n){
- if(front == null){
- front = new ListNode(n,null);
- } else {
- ListNode cur = front;
- while(cur.getNext() != null){
- cur = cur.getNext();
- }
- cur.setNext(new ListNode(n,null));
- numNodes++;
- }
- }
- public ListNode getFront(){
- return front;
- }
- public void printOut(){
- ListNode cur = front;
- while(cur.getNext() != null){
- System.out.println(cur.getValue());
- cur=cur.getNext();
- }
- System.out.println(cur.getValue());
- System.out.println("=====================");
- }
- public ListNode getKthNode(int k){
- ListNode cur = front;
- for(int i = 0; i < k; i++){
- if(cur.getNext() != null){
- cur = cur.getNext();
- }
- }
- if(cur != null){
- return cur;
- }
- return null;
- }
- public void transferNodesFromEnd(WaitingList other, int num){
- ListNode last = getKthNode(size()-1);
- int i = num;
- while(i < other.size()){
- last.setNext(other.getKthNode(i));
- numNodes++;
- i++;
- last = last.getNext();
- }
- //leom hertzberg certified code
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement