📄 functions.c
字号:
#include<malloc.h>
#include<stdio.h>
#include"definition.h"
LinkList FormList()//正向形成链表
{
LinkList h, head, end;
ElemType temp;
if( !( h=head=(LinkList)malloc(sizeof(Node)) ) ){
printf("Not Enough Memory!\n");
return 0;
}
h->next=h->prior=h;
while( (temp=getchar())!='\n' ){
if( !( end=(LinkList)malloc(sizeof(Node)) ) ){
printf("Not Enough Memory!\n");
return 0;
}
end->data=temp;
end->next=h;
end->prior=head;
head->next=end;
head=end;
h->prior=end;
}
return h;
}
void Insert(LinkList L, unsigned i)//插入数据
{//若单链表没有头结点,需对在第一个结点之前进行插入的情况单独进行处理。很麻烦
LinkList T, A=L;
ElemType temp;
getchar();
while(--i){
L=L->next;
if( !(L-A) )
break;
}
if(i&&!(L-A)){
printf("Error!\n");
return;
}
printf("请输入您要插入的数据:");
while( (temp=getchar())!='\n' ){
if( !( T=(LinkList)malloc(sizeof(Node)) ) ){
printf("Not Enough Memory!\n");
return;
}
T->data=temp;
T->next=L->next;
A=L->next;
A->prior=T;
T->prior=L;
L->next=T;
L=T;
}
}
void Delete(LinkList L, unsigned i, unsigned j)//删除数据
{
LinkList T, A, B=L;
getchar();
while(--i){
L=L->next;
if( !(L-B) )
break;
}
if(i&&!(L-B)){
printf("Error!\n");
return;
}
for(T=L->next; j&&(T-B); j--){
L->next=T->next;
A=T->next;
A->prior=L;
free(T);
T=L->next;
}
}
void Disp(LinkList L)//显示数据
{
LinkList T=L;
for(L=L->next; L-T; L=L->next)
printf("%c", L->data);
printf("\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -