/* * 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 boolean search(String s) { return recSearch(s, head); } private boolean recSearch(String s, Node n) { // look for s in the portion of the linked list // from n to the tail if (n == null) return false; if (s.equals(n.getElement())) return true; return recSearch(s,);//fill in the missing argument } public void removeFirst() { if (head == null) return; head = head.getNext(); size--; if (size == 0) tail = null; } public void printList() { Node temp = head; while (temp != null) { System.out.println(temp.getElement()); temp = temp.getNext(); } } /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here SLinkedList l = new SLinkedList(); l.addFirst("Bob"); l.addFirst("Alice"); l.addFirst("Jack"); System.out.println(l.search("Mr. Brown")); System.out.println(l.search("Jack")); } }