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

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个回答

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

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐