emm,太多了,放不下main了
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
typedef struct node//节点,双向循环链表
{
int num;
struct node *pre;
struct node *next;
} node;
void Init(node *head, int n)//初始化
{
//n是num的位数,其符号代表num的符号,位数
head->next = head;
head->pre = head;
head->num = n;
}
void Insert(node *head, int e, int pos)
{
//插在第pos个节点之后
node *s = (node *)malloc(sizeof(node));//申请节点
if (s == NULL)
{
printf("malloc fail in Insert");
return;
}
s->num = e;
node *p = head;
for (int i = pos; i > 1; i--)//找位置
{
p = p->next;
}
s->next = p->next;//插入
p->next = s;
s->next->pre = s;
s->pre = p;
}
int length(node *head)//返回链表长度
{
node *p = head;
int len = 1;
while (p->next != head)//遍历
{
len++;
p = p->next;
}
return len;
}
void read(node *head, int m)//从键盘读入数据
{
int e;
int n = abs(m);//去掉符号
switch (n % 4)
{
case 1://若是1/5/9之类的
scanf("%1d", &e);//首位只存一位数字
Insert(head, e, length(head));
for (int i = abs(n - 1) / 4; i > 0; i--)//假如是9,需要三个节点存储,(除首位外)每个节点存储一个四位数
{
scanf("%4d", &e);
Insert(head, e, length(head));
}
break;
case 2://若是2/6/10之类的
scanf("%2d", &e);//首位存两位数字
Insert(head, e, length