tenkobility
2017-11-27 02:36数据结构双链表的插入和删除有问题了,求大佬看看
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条回答
为你推荐
- 求求大佬帮忙看下哪里出了问题,实在不知道了
- 搜索引擎
- c语言
- c++
- 测试用例
- 1个回答
- c语言链表相关问题,跪求大佬解惑
- c语言
- 4个回答
- 小白求问,有没有大佬看看这个错哪了
- java
- java-ee
- 2个回答
- 新手上路,有个问题请教各位大佬,帮看看呗
- c++
- 1个回答
- 求大佬看看c语言求n到m之间的素数并求素数和
- c语言
- 1个回答
换一换