62,621
社区成员
发帖
与我相关
我的任务
分享
public void delete(String input)
{
LinkedStack<String> addrStack = splitStr(input);
......
}
private static LinkedStack<String> splitStr(String input)
{
LinkedStack<String> addrStack = new LinkedStack<String>();
String[] s = input.split("\\.");
for (int i = 0; i < s.length; i++)
{
if (i != s.length - 1)
addrStack.push(s[i] + ".");
else
addrStack.push(s[i]);
}
return addrStack;
}
public class LinkedStack<E> implements Cloneable
{
private Node<E> top;
public LinkedStack()
{
top = null;
}
public LinkedStack<E> clone()
{
LinkedStack<E> answer;
try
{
answer = (LinkedStack<E>) super.clone();
} catch (CloneNotSupportedException e)
{
throw new RuntimeException(
"This class does not implements Cloneable");
}
answer.top = Node.listCopy(top);
return answer;
}
public boolean isEmpty()
{
return (top == null);
}
public E peek()
{
if (top == null)
throw new EmptyStackException();
return top.getData();
}
public E pop()
{
E answer;
if (top == null)
throw new EmptyStackException();
answer = top.getData();
top = top.getLink();
return answer;
}
public void push(E item)
{
top = new Node<E>(item, top);
}
public int size()
{
return Node.listLength(top);
}
}