hi ,I rellay need your help.
here when i type "rmdir"
it takes the valur i print but i dont send it !?
please help
and its "doubly linked list"
code:LLTest
Code:[CODE]import java.io.*;
import java.util.*;
public class LLTest
{
public static void main(String args[])
{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
LL theList=new LL();
//// /////////////////////////////////////////////////////////////
String input=" ";
int inputcount=0;
String command=" ";
String value=" ";
////////////////////////////////////////////////////////////////////////////
do{
System.out.println(" ");
System.out.print("Enter the new node value or exit to quit: ");
try
{
input =in.readLine();
System.out.println(" ");
}//end try
catch(Exception semo)
{
System.out.println("error");
System.exit(1);
}
// if(input.equals("exit"))
// break;
//////////////////////////////////////////////////
///////////////////////////////////////////////
StringTokenizer st = new StringTokenizer(input);
inputcount=st.countTokens() ;
command=st.nextToken();
if(command.equals("mkdir"))
{
if(st.hasMoreTokens())
{
value=st.nextToken();
if(theList.Chick(value)) {
theList.insertlast(value);
System.out.println(" ");
System.out.println("Create new directory "+value);
System.out.println(" ");
theList.print();
}//end 3 if
else{
System.out.println("Error The node already exist");
}
}//end 2 if
else
{
System.out.println("Error in Directory node ");
}
}//end 1 if
else if(command.equals("rmdir"))
{
if(st.hasMoreTokens())
{
value=st.nextToken();
theList.delete(value);
theList.print();
if(!theList.Chick(value)) {
System.out.println(" ");
System.out.println(" delete directory "+value);//
theList.delete(value);
System.out.println(" ");
theList.print();
}
}//end 3 if
else
{ theList.delete(value);
System.out.println(" ");
System.out.println(" delete directory "+value);//
System.out.println(" ");
//System.out.println("Error");
}
}
}while(!input.equals("exit"));
}
}
//end class[/CODE]
code :LL
Code:public class LL
{// private Node first;
// private Node last;
private Node first=new Node();
private Node last=first;
public boolean isEmpty()
{
return(first==null);
}
public void insertlast( String iData)
{
Node newNode =new Node(iData );
if(isEmpty())
{
first=newNode;
// last=newNode;
}
else
{ last.next=newNode;
newNode. previous=last;
// ast=newNode; l//on both type
}
last=newNode;
}
public Node delete(String key)
{ Node current = first.next;
while(current.item!= key)
{current=current.next ;
if(current==null)
return null;
}
if(current.next==null)
{last.previous.next=null ;
last=current.previous ;}
else
{
while(last!=current)
{
last.previous.next=null ;
last=last.previous;
}
last.previous.next=null ;
last=current.previous;
}
return current;
}
public void print()
{ Node temp=first;
while(temp!=null)
{ System.out.printf("<%s> ",temp.item);
temp=temp.next;
}
System.out.println("");
}
public boolean Chick(String newNode)
{
Node temp=first;
while(temp!=null)
{
if(newNode.equalsIgnoreCase(temp.item) ) //here I do not know what is the condition
return false;
temp=temp.next;
}//end while
return true;
}//end method
/* public static void main (String args[])
{
LL ob =new LL () ;
ob.insertlast("a");
ob.insertlast("b");
ob.insertlast("c");
ob.insertlast("d");
ob.print();
// ob.delete("d");
// ob.print();
ob.delete("b");
ob.print();
}*/
}
