在堆栈中,push为入栈操作,pop为出栈操作

时间:2023-03-09 09:47:33
在堆栈中,push为入栈操作,pop为出栈操作

LinkedList提供以下方法:(ArrayList无此类方法)

addFirst();

removeFirst();

addLast();

removeLast();

在堆栈中,push为入栈操作,pop为出栈操作。

Push用addFirst();pop用removeFirst(),实现后进先出。

用isEmpty()--其父类的方法,来判断栈是否为空。

在队列中,put为入队列操作,get为出队列操作。

Put用addFirst(),get用removeLast()实现队列。

 package TomTexts;

 public class TomTexts_11 {
public static void main(String[] args)
{
String s1="Javav";
char c=s1.charAt(2);
System.out.println("c="+c);
int i=s1.indexOf('a');
System.out.println("fistchar="+i);
int j=s1.lastIndexOf('a');
System.out.println("lastchar="+j);
i= s1.indexOf("av");
System.out.println("fiststring="+i);
j=s1.lastIndexOf("av");
System.out.println("laststring="+j);
}
}

相关文章