tenkobility 2017-11-27 02:36 采纳率: 0%
浏览 1121

数据结构双链表的插入和删除有问题了,求大佬看看

void insert(double price, int number,int time,char* name,int date,int id)
{
movRecord* node = record.next;
movRecord* p = record.next;

while (node != NULL)
{
        if (node->id > id)  break;
        else
        node = node->next;
}
movRecord* tmp = (movRecord *)malloc(sizeof(movRecord));
tmp->id = id;
tmp->date = date;
strcpy(tmp->name,name);
tmp->time = time;
tmp->number = number;
tmp->price = price;   
    if( id<10)
{

node->prior->next= tmp;
tmp->prior=node->prior;
tmp->next = node;
node->prior=tmp;
}
 else
{     
node->prior->next=tmp;
tmp->prior=node;
tmp->next=NULL;

}

while(p!=NULL)
{
    printf("电影编号:%3d\t放映日期:%10d\t电影名:%5s\t场次:%2d\t票数量:%4d\t票价:%5.2lf\t\n", 
    p->id, p->date,p->name,p->time,p->number,p->price);
    p=p->next;
}

}

void delete(int id)
{
movRecord* node = record.next;
movRecord* p=record.next;
while (node != NULL && node->id != id)
{
node = node->next;
}
if (node)
{
node->prior->next = node->next;
node->next->prior = node->prior;
free(node);
}

else
    printf("无法找到该文件\n");  

while(p!=NULL)
{
    printf("电影编号:%3d\t放映日期:%10d\t电影名:%5s\t场次:%2d\t票数量:%4d\t票价:%5.2lf\t\n",
     p->id, p->date,p->name,p->time,p->number,p->price);
    p=p->next;
}

}

  • 写回答

1条回答

  • 小明学编程 2018-01-08 12:05
    关注

    不知道你其他的代码是怎么样子的。头结点和尾节点,在插入和删除的时候,要特殊对待的。

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题