public class SingleList { SNode head = null; SNode tail = null; //Below is the Node class to be used for packets in //a singly linked list private class SNode { Packet p; // packet reference SNode next; //next pointer //Constructor for a Node, default private SNode (Packet p) { setPacket(p); this.next = null; } private void setNext(SNode s){ this.next = s; } private void setPacket (Packet p) { this.p = p; } } //pre - p is a valid packet //post - a new node containing p has been added to the // end of the linked list public void addNode(Packet p){ SNode s = new SNode(p); if (head ==null) { head = s; tail = s; } else { tail.setNext(s); tail = s; } } //post - if the list is empty, it returns "List empty\n" // if the list is not empty, it adds each packet to string along with // a \n after the packet public String toString() { if (head == null) return "List empty\n"; String sr = ""; SNode s = head; while (s != null) { sr = sr + s.p + "\n"; s = s.next; } return sr; } // Use this main to test your list public static void main (String[] args) { SingleList s1 = new SingleList(); System.out.println (s1); Packet p1 = new Packet(); p1.setPkPacketID(1); p1.setPkDestPort(0); p1.setPkServiceLevel(Packet.ServiceLevel.HIGH); p1.setPkPayload("asfasdf"); s1.addNode(p1); System.out.println (s1); Packet p2 = new Packet(); p2.setPkPacketID(2); p2.setPkDestPort(1); p2.setPkServiceLevel(Packet.ServiceLevel.NORMAL); p2.setPkPayload("asfasdf"); s1.addNode(p2); System.out.println (s1); } }