📄 dulinklist.cpp
字号:
#include "stdio.h"
#include "stdlib.h"
#define OVERFLOW 0
#define OK 1
#define TRUE 1
#define ERROR 0
typedef int ElemType;
typedef int Status;
typedef struct DuLNode{
ElemType data;
struct DuLNode * prior;
struct DuLNode * next;
}DuLNode,* DuLinkList;
Status Init_DuLinkList(DuLinkList &H)
{
H=(DuLNode *)malloc(sizeof(DuLNode));
if(!H)
return OVERFLOW;
H->data=100;
H->prior=H;
H->next=H;
return OK;
}
void Input(DuLinkList &H,int n)
{
DuLNode *t;
if(H->next=H)
t=H;
else
{
t=H->next;
while(t->next!=H)
t=t->next;
}
for(int i=0;i<n;i++)
{
DuLNode *p=0;
p=(DuLNode *)malloc(sizeof(DuLNode));
printf("Input:"); scanf("%d",&(p->data));
t->next=p;
H->prior=p;
p->prior=t;
p->next=H;
t=t->next;
}
}
void Print(DuLinkList H)
{
DuLNode *p;
p=H->next;
while(p!=H)
{
printf("%4d",p->data);
p=p->next;
}
}
Status panduan(DuLinkList H)
{
DuLNode *p,*q;
p=H->next;
q=H->prior;
while(p!=q)
if(p->data==q->data)
{
p=p->next;
q=q->prior;
}
else return(0);
return(1);
}
void main()
{
int i;
DuLinkList H;
Init_DuLinkList(H);
Input(H,8);
Print(H);
printf("\n");
i=panduan(H);
if(i==1)
printf("对称\n");
else
printf("不对称\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -