//------------// Introduction to Programming Using Java: An Object-Oriented Approach//	Arnow/Weiss//------------// the search method// Chapter 10, Section 10.4, Page 393// MODIFICATIONS://    search and moveToFront are made static here so we//    can test them without creating an object//    main creates a Vector of Strings from input and then tests to see if//	each String can be found in the Vector.import java.io.*;import java.util.*;class TestmoveToFront {	private static void  moveToFront(Vector  v,  int  k)  {		v.insertElementAt(v.elementAt(k),0);		v.removeElementAt(k+1);	}	private static int search(String s) {	// Returns the index of a match to s in v						//    or -1 if there is no match		int k;	// k== the index of the next position in 			//      the vector to check.			// No match has been found in 			//      positions 0 through k-1.		k = 0;		while (!(k==v.size() || s.equals(v.elementAt(k))))			k++;		// k==v.size() || s.equals(v.elementAt(k))		if (k==v.size())			return -1;		else {			moveToFront(v,k);	// Found a match at position k, so 						//      move it to the front.			return 0;		}	}	public static void main(String[] a) throws Exception {		boolean fails=false;		BufferedReader f = new BufferedReader(new InputStreamReader(System.in));		v = new Vector();		String line = f.readLine();		String huge = "";		while (line != null) {			huge = huge.concat(line);			v.addElement(line);			line = f.readLine();		}		int k=0;		while (k != v.size()) {			if (search((String)v.elementAt(k))!=0) {				System.err.println("search failure");				fails = true;			}			k++;		}		k=0; // test twice to verify integrity of Vector after MTF		while (k != v.size()) {			if (search((String)v.elementAt(k))!=0) {				System.err.println("search failure");				fails = true;			}			k++;		}		if (search(huge)!=-1) {			System.err.println("search failure");			fails = true;		}		if (!fails)			System.out.println("search passes these tests");	}	static Vector v;}// Sample test input (no duplicates allowed!)// butter// mustard// ketchup// abc// x// z// antidisestablishmentarianism