C语言三个链表的关联,有能者相互切磋---怎样实现ABC三个链表的相互操作?

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

接着是三张链表的定义:

/**

* 延时链表

*

*/

#include

#include"DoubleList.h"

//#include "WaitingList.h"

#include

//创建双向链表

void CreatDoubleLinkList(int headNum);

void CreatWaitingList(int headNum);

//创建节点

void CreatNewDot(PDB *newDot,int nTCnt);

//查找

PDB SearchDot(int nTCnt);

//插入

void InsertDot(PDB dot,int AfterNum);

//删除

void DeleteDot(int nTCnt);

//修改

void UpdateDot(int originNum,int changeNum);

//输出打印信息

void printInfo();

int inputNum=0;

int chanNum=0;

int order=-1;

int main()

{

do

{

printf("***********************命令菜单***************************\n");

printf("*** ***\n");

printf("***********************1:创建延时链表头节点***************\n");

printf("*** ***\n");

printf("***********************2:创建新节点***********************\n");

printf("*** ***\n");

printf("***********************3:修改节点值***********************\n");

printf("*** ***\n");

printf("***********************4:删除节点*************************\n");

printf("*** ***\n");

printf("***********************5:打印现在列表的值*****************\n");

printf("*** ***\n");

printf("***********************6:退出程序*************************\n");

printf("请输入命令:\n");

scanf("%d",&order);

switch(order)

{

case 1:

printf("请输入头结点的值:\n");

scanf("%d",&inputNum);

CreatDoubleLinkList(inputNum);

break;

case 2:

printf("请输入新结点的值:\n");

scanf("%d",&inputNum);

CreatNewDot(&newDot,inputNum);

printf("请输入你要插在那个节点之后:\n");

scanf("%d",&inputNum);

InsertDot(newDot,inputNum);

break;

case 3:

printf("请输入要修改的节点的原来的值:\n");

scanf("%d",&inputNum);

printf("请输入要修改后值:\n");

scanf("%d",&chanNum);

UpdateDot(inputNum,chanNum);

break;

case 4:

printf("输入要删除的节点的值:\n");

scanf("%d",&inputNum);

DeleteDot(inputNum);

break;

case 5:

printInfo();

break;

case 6:

exit(0);

default:

break;

}

}while(order!=6);

return 0;

}

//创建延时双向链表

void CreatDoubleLinkList(int headNum)

{

Head=(PDB)malloc(LEN);

Head->nTCnt=headNum;

Head->next=Head->previous=Head;

printf("双向链表的头结点已经创建,值为:%d\n",Head->nTCnt);

}

//创建阻塞双向链表

//CreatWaitingList(int headNum)

//{

//Head=(PTCB)malloc(LEN);

// Head->DeadLine=headNum;

// Head->next=Head->previous=Head;

// printf("双向链表的头结点已经创建,值为:%d\n",Head->DeadLine);

//}

//创建节点

void CreatNewDot(PDB *newDot,int number)

{

(*newDot)=(PDB)malloc(LEN);

(*newDot)->nTCnt=number;

}

//打印信息

void printInfo()

{

if(Head==NULL)

{

printf("链表为空!\n");

return ;

}

PDB pOut=Head;

printf("链表值为:\n");

do{

printf("%d\n",pOut->nTCnt);

pOut=pOut->next;

}while(pOut->next!=Head->next);

}

//查找信息

PDB SearchDot(int num)

{

if(Head==NULL)

{

printf("链表为空,没有可以删除的节点!\n");

return NULL;

}

else if(Head->nTCnt==num)

{

return Head;

}

else

{

PDB search=Head->next;

while(search->nTCnt!=num&&search!=Head)

{

search=search->next;

}

if(search==Head)

return NULL;

else

return search;

}

return NULL;

}

//插入节点

void InsertDot(PDB dot,int AfterNum)

{

if(dot==NULL)

return ;

else

{

PDB AfterDot=SearchDot(AfterNum);

dot->previous=AfterDot;

dot->next=AfterDot->next;

AfterDot->next->previous=dot;

AfterDot->next=dot;

}

printf("数据插入成功!\n");

}

//删除节点

void DeleteDot(int num)

{

PDB delDot=SearchDot(num);

if(delDot==NULL)

{

printf("节点不存!\n");

return ;

}

delDot->previous->next=delDot->next;

delDot->next->previous=delDot->previous;

free(delDot);

printf("节点删除成功!\n");

}

//修改节点

void UpdateDot(int originNum,int changeNum)

{

PDB chanDot=SearchDot(originNum);

if(chanDot==NULL)

{

printf("不存在节点值为:%d 的节点!\n",originNum);

return ;

}

else

{

chanDot->nTCnt=changeNum;

printf("节点值更改成功!\n");

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值