pku 1028

题意:模拟游览器的前进和后退。

注重点:对数据结构的基本掌握,用双向链表实现的

代码来源:大萎的代码直接交的。

代码:

#include <stdio.h>
#include <string.h>

typedef struct link
{
 char Address[70];
 struct link *prior;
 struct link *next;
}Link;

Link* Head;
Link* V;

void InitLink()
{
 Head = new(Link);
 strcpy(Head->Address,"http://www.acm.org/");
 Head->prior = NULL;
 Head->next =NULL;
 V = Head;
}

void Insert()
{
 Link* q;
 q = new(Link);
 scanf("%s",q->Address);
 q->next = NULL;
 q->prior =NULL;
 if(Head->next == NULL)
 {
  Head->next = q;
  q->prior = Head;
  V = q;
 }
 else
 {
  if(V->next != NULL)
   V->next->prior = q;
  V->next = q;
  q->prior = V;
  V = q;
 }
 
}

int main()
{
 InitLink();
 char Call[10];
 scanf("%s",Call);
 while(strcmp(Call,"QUIT") != 0)
 {
  if(strcmp(Call,"VISIT") == 0)
  {
   Insert();
   printf("%s/n",V->Address);
  }
  if(strcmp(Call,"BACK") == 0)
  {
   if(V->prior == NULL)
    printf("Ignored/n");
   else
   {
    V = V->prior;
    printf("%s/n",V->Address);
   }
  }
  if(strcmp(Call,"FORWARD") == 0)
  {
   if(V->next == NULL)
    printf("Ignored/n");
   else
   {
    V = V->next;
    printf("%s/n",V->Address);
   }
  }
  if(strcmp(Call,"QUIT") == 0)
   break;
  scanf("%s",Call);
 }
 return (0);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值