/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package slinkedlist; /** * * @author kvaradar */ public class SLinkedList { protected Node head, tail; protected long size; public SLinkedList() { head = null; tail = null; size = 0; } public void addFirst(String s){ Node temp = head; head = new Node(s,null); head.setNext(temp); if (size == 0) { tail = head; } size++; //head = new Node(s,head); } public void addLast(String s) { } public void removeFirst() { head = head.getNext(); size--; if (size == 0) tail = null; } public void removeLast(){ } public void printList() { Node temp = head; while (temp != null) { System.out.println(temp.getElement()); temp = temp.getNext(); } } public boolean contains(String s){ return true; } public static void main(String[] args) { SLinkedList l = new SLinkedList(); l.addFirst("Bob"); l.addFirst("Alice"); l.addFirst("Jack"); l.printList(); l.removeFirst(); l.printList(); l.removeFirst(); l.removeFirst(); l.printList(); } }