Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:用java自带Stack实现的代码,请大家多多指教

Posted by SDRJ102010010368 at 2013-04-24 15:35:32 on Problem 1028
In Reply To:用java自带Stack实现的代码,请大家多多指教 Posted by:lg8t4bysq8 at 2006-11-11 20:03:32
> import java.util.Scanner;
> import java.util.Stack;
> 
> public class Main {
> 	
> 	public static void main(String[] args) {
> 		Stack forwardStack=new Stack();
> 		Stack backwardStack=new Stack();
> 		String currentPage="http://www.acm.org/";
> 		String url;
> 		String cmd;
> 		Scanner sin=new Scanner(System.in);
> 		while(true)
> 		{
> 			
> 			cmd=sin.next();
> 			if(cmd.equals("VISIT"))
> 			{
> 				backwardStack.push(currentPage);
> 				url=sin.next();
> 				currentPage=url;
> 				forwardStack.clear();
> 				System.out.println(currentPage);
> 			}
> 			else if(cmd.equals("BACK"))
> 			{
> 				
> 				
> 				
>                 if(backwardStack.isEmpty())
>                 {
>                 	System.out.println("Ignored");
>                 }
>                 else
>                 {
>                 	forwardStack.push(currentPage);
>                 	currentPage=(String)backwardStack.pop();
>                 	System.out.println(currentPage);
>                 }
>                 
> 			}
> 			else if(cmd.equals("FORWARD"))
> 			{
> 		         
> 				
>                 if(forwardStack.isEmpty())
>                 {
>                 	System.out.println("Ignored");
>                 }
>                 else
>                 {
>                 	backwardStack.push(currentPage);
>                 	currentPage=(String)forwardStack.pop();
>                 	System.out.println(currentPage);
>                 }
> 				
> 			}
> 			else if(cmd.equals("QUIT"))
> 			{
> 				break;
> 			}
> 		}
> 	}
> 
> }

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator