Wwerday 2022-04-10 15:31 采纳率: 100%
浏览 8
已结题

为啥跑不出来,我觉得可能是去除head1中元素时错了,但不知道哪错了

img


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>

typedef struct node {
    int data;
    struct node* next;
}Node;

void CreatList(Node* head, int a) {
    Node* temp;
    temp = (Node*)malloc(sizeof(Node));
    temp = head;

    for (int i = 0; i < a; i++) {
        temp->next = (Node*)malloc(sizeof(Node));
        scanf("%d", &temp->next->data);
        temp = temp->next;
    }

    temp->next = NULL;
}

void Function(Node* head1, Node* head2, Node* head3) {
    Node *temp1, *temp2, *temp3;
    temp1 = head2->next;
    temp2 = head3->next;
    temp3 = head1;
    int A[100] = { -999999999 }, i = 0, j = 1;
//找出head2和head3中的相同元素
    while (temp2 && temp1) {
        while (temp2 != NULL && temp1 != NULL && temp1->data != temp2->data) {
            if (temp1->data > temp2->data) {
                temp2 = temp2->next;
            }
            else {
                temp1 = temp1->next;
            }
        }

        if (temp1 == NULL || temp2 == NULL) {
            break;
        }
        else {
            A[i+1] = temp1->data;
            temp1 = temp1->next;
            temp2 = temp2->next;
            i++;
        }
    }
//去除head1中的元素
    while (temp3->next) {
        if (A[j] == 0 && temp3->next != NULL) {
            break;
        }
        while (temp3->next->data < A[j] && temp3->next != NULL) {
            temp3 = temp3->next;
            printf("%d",temp3);
        }
        if (temp3->next->data == A[j] && temp3->next != NULL) {
            Node* p = temp3->next;
            temp3->next = p->next;
            free(p);
        }
        j++;
    }

}

void Print(Node* head) {
    Node* p = head->next;
    while (p) {
        printf("%d ", p->data);
        p = p->next;
    }

}

int main()
{
    int m, n, p;
    struct node* head1 = NULL, *head2 = NULL, *head3 = NULL;
    head1 = (Node*)malloc(sizeof(Node));
    head2 = (Node*)malloc(sizeof(Node));
    head3 = (Node*)malloc(sizeof(Node));
    scanf("%d%d%d", &m, &n, &p);
    CreatList(head1, m);
    CreatList(head2, n);
    CreatList(head3, p);
    Function(head1, head2, head3);
    Print(head1);
    return 0;
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 4月18日
    • 创建了问题 4月10日

    悬赏问题

    • ¥20 有没有人会这个东西的
    • ¥15 cfx考虑调整“enforce system memory limit”参数的设置
    • ¥30 航迹分离,航迹增强,误差分析
    • ¥15 Chrome Manifest扩展引用Ajax-hook库拦截请求失败
    • ¥15 用Ros中的Topic通讯方式控制小乌龟的速度,走矩形;编写订阅器代码
    • ¥15 LLM accuracy检测
    • ¥15 pycharm添加远程解释器报错
    • ¥15 如何让子窗口鼠标滚动独立,不要传递消息给主窗口
    • ¥15 如何能达到用ping0.cc检测成这样?如图
    • ¥15 关于#DMA固件#的问题,请各位专家解答!