| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
我是个初学者,望牛人指点。代码很详细,纯栈操作....#include<iostream>
#include<string.h>
#include<malloc.h>
using namespace std;
typedef struct web
{
char data[105][75];
int top;
}Forword,Backword,Listack;
void Initstack(Listack *&S)
{
S=(Forword *)malloc(sizeof(Forword));
S->top=-1;
}
void Push(Listack *&S,char *p)//进栈
{
S->top++;
strcpy(S->data[S->top],p);
}
int Pop(Listack *&S,char *p)//出栈
{
if(S->top==-1)
{
cout<<"Ignored"<<endl;
return 0;
}
else
{
strcpy(p,S->data[S->top]);
S->top--;
return 1;
}
}
void Destorystack(Listack *&S)
{
free(S);
}
int main()
{
Forword *S1;
Backword *S2;
Initstack(S1);
Initstack(S2);
char cur[71]="http://www.acm.org/";
char ch1[10],ch2[71];
cin>>ch1;
while(strcmp(ch1,"QUIT")!=0)
{
if(strcmp(ch1,"VISIT")==0)
{
cin>>ch2;
Push(S2,cur);
strcpy(cur,ch2);
cout<<cur<<endl;
Destorystack(S1);
Initstack(S1);
}
else if(strcmp(ch1,"BACK")==0)
{
if(strcmp(cur,"http://www.acm.org/")!=0)
Push(S1,cur);
if(Pop(S2,cur))
cout<<cur<<endl;
}
else if(strcmp(ch1,"FORWARD")==0)
{
Push(S2,cur);
if(Pop(S1,cur))
cout<<cur<<endl;
}
cin>>ch1;
}
Destorystack(S1);
Destorystack(S2);
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator