MiKi同学 2020-10-09 14:23 采纳率: 0%
浏览 53

求大佬看看为什么输出不了结果

#include
#include
#include
#define MaxSize 100
#define ElemType int
#define Status int
using namespace std;

typedef struct node
{
ElemType data;
node* next;
}node, * LinkList;

Status InitList(LinkList& L)
{
L = new node;
L->next = NULL;
return 1;
}

int ListLength(LinkList& L)
{
LinkList p = L;
int sum = 0;
while (p)
{
sum++;
p = p->next;
}
return sum - 1;
}

void CreatList(LinkList& L)
{

int i = 0; int choice;
int a[MaxSize];
ifstream infile;
cout << "请选择要给链表赋值的文件(test1 or test2):";
cin >> choice;
switch (choice)
{
case 1:infile.open("Test1.txt"); break;
case 2:infile.open("Test2.txt"); break;
default:cout << "输入错误"; break;
}
while (infile.good())
{
    infile >> a[i];
    i++;
}
infile.close();
sort(a, a + i);
LinkList head = new node;
head->next = NULL;
node* tail = new node;
head=tail;
for (int n = 0; n < i; n++)
{
    node* p = new node;
    p->data = a[n];
    p->next = NULL;
    tail->next = p;
    tail = tail->next;
}
node* t = new node;
t = head;
int f = 0;
cout << "链表输出为:";
while (t->next != NULL)
{
    if (f == 0)
    {
        cout << t->next->data;
        f++;
        t = t->next;
    }
    else
    {
        cout << " " << t->next->data;
        f++;
        t = t->next;
    }
}
L = head;
cout << endl;

}

void Display(LinkList L)
{
if (L == NULL) return;
LinkList p = L->next;
while (p != NULL)
{
cout << p->data << " ";
p = p->next;
}
}

void CombineList(LinkList L1, LinkList L2,LinkList L3)
{
node* p = new node;
node* q = new node;
node* r = new node;
p = L1->next;
q = L2->next;
r = L3;
L3 = L1;
while (p&&q)
{
if (p->data < q->data)
{
r->next = q;
r = q;
q = q->next;
}
else
{
r->next = p;
r = p;
p->next = p;
}
}
r->next = p ? p : q;
delete L2;
cout << "合并后的链表为:";

}

int main()
{
LinkList LA, LB,LC;
InitList(LA);
InitList(LB);
InitList(LC);
CreatList(LA);
CreatList(LB);
CombineList(LA, LB,LC);
Display(LC);

return 0;

}

  • 写回答

1条回答 默认 最新

  • threenewbee 2020-10-09 15:51
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 找一个QT页面+目标识别(行人检测)的开源项目
  • ¥15 有没有整苹果智能分拣线上图像数据
  • ¥20 有没有人会这个东西的
  • ¥15 cfx考虑调整“enforce system memory limit”参数的设置
  • ¥30 航迹分离,航迹增强,误差分析
  • ¥15 Chrome Manifest扩展引用Ajax-hook库拦截请求失败
  • ¥15 用Ros中的Topic通讯方式控制小乌龟的速度,走矩形;编写订阅器代码
  • ¥15 LLM accuracy检测
  • ¥15 pycharm添加远程解释器报错
  • ¥15 如何让子窗口鼠标滚动独立,不要传递消息给主窗口