zoukankan      html  css  js  c++  java
  • 2054=数据结构实验之链表九:双向链表

     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 struct node
     4 {
     5     int data;
     6     struct node*next,*last;
     7 };
     8 int main()
     9 {
    10     int m,n,x,i,a;
    11     struct node*head,*p,*end;
    12     head=(struct node*)malloc(sizeof(struct node));
    13     head->next=NULL;
    14     end=head;
    15     scanf("%d %d",&n,&m);
    16     for(i=0; i<n; i++)
    17     {
    18         p=(struct node*)malloc(sizeof(struct node));
    19         scanf("%d",&p->data);
    20         p->next=NULL;
    21         end->next=p;
    22         p->last=end;//双向链表其实和单向链表没啥区别,就是在下一个加了一个(上一个)。
    23         end=p;
    24     }
    25     for(i=0; i<m; i++)
    26     {
    27         scanf("%d",&a);
    28         for(p=head->next; p; p=p->next)//这里是head不是NULL;
    29         {
    30             if(p->data==a)
    31             {
    32                 if(p->last!=head&&p->next!=NULL)printf("%d %d
    ",p->last->data,p->next->data);
    33                 else if(p->last!=head)printf("%d
    ",p->last->data);
    34                 else if(p->next!=NULL)printf("%d
    ",p->next->data);
    35             }
    36         }
    37     }
    38     return 0;
    39 }
  • 相关阅读:
    Hadoop无法访问web50070端口
    Hadoop问题汇总
    Hadoop问题汇总
    Linux网络连接模式以及修改静态IP
    Linux网络连接模式以及修改静态IP
    Linux基本命令
    SQLite数据操作
    SQLite初试
    编码与解码
    属性列表
  • 原文地址:https://www.cnblogs.com/Angfe/p/10485243.html
Copyright © 2011-2022 走看看