⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 slnode.h

📁 我的一个课程设计
💻 H
字号:
typedef struct Node
{
DataType data;
struct Node *next;
struct Node *prior;
}SLNode;


void ListInitiate(SLNode **head)
{
if ((* head=(SLNode *)malloc(sizeof(SLNode)))==NULL)exit(1);
(*head)->next=*head;
(*head)->prior=*head;
}

int ListLength(SLNode *head)
{
SLNode *p=head;
int size=0;
while (p->next!=head)
{
p=p->next;
size++;
}
return size;
}

int ListInsert(SLNode *head,int i,DataType x)
{
SLNode *p,*q;
int j=0;
p=head->next;
while(p!=head&&j<i)
{
p=p->next;
j++;
}
if(j!=i)
{
printf("插入位置出错!!");
return 0;
}

if((q=(SLNode *)malloc(sizeof(SLNode)))==NULL)exit(0);
q->data=x;
q->prior=p->prior;
p->prior->next=q;
q->next=p;
p->prior=q;
return 1;

}

int ListDelete(SLNode *head,int i)
{
SLNode *p;
p=head->next;
int j=0;
while(p!=head&&j<i)
{
p=p->next;
j++;
}
if(j!=i)
{
printf("删除位置出错!");
return 0;
}
p->prior->next=p->next;
p->next->prior=p->prior;
free(p);
return 1;
}

void Destory(SLNode **head)
{
SLNode *p,*q;
int n;
n=ListLength(*head);
p=*head;
for(int i=0;i<=n;i++)
{
q=p;
p=p->next;
free(q);
}
*head=NULL;
}

int ListGet(SLNode *head,int i,DataType *x)
{
SLNode *p;
p=head->next;
int j=0;
while(p!=head&&j<i)
{
p=p->next;
j++;
}
if(j!=i)
{
printf("位置出错!");
return 0;
}
*x=p->data;
return 1;

}





⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -