user-0 提问: 【求助】代码引发异常:读取访问权限冲突

回复:
user: user-0
content: 引用//运行结果：   //input list a: //input number & scores of student: //if number is 0,stop inputing. //1,60 //4,80 //0 //input list b: //input number & scores of student: //if number is 0,stop inputing. //3,90 //6,70 //0 //There are 4 records: //1 60 //3 90 //4 80 //6 70 //请按任意键继续. . .  某些测试数据没有排序

user: user-1
content: 试验了下，结果如下，供参考：//链表a 和 链表b 应该都是顺序链表，不存在楼主输入倒序的问题，下面是两次运行的例子，第二次的存在问题.  //第一次输入：  //input list a: //input number & scores of student: //if number is 0,stop inputing. //3,78 //7,88 //0 //input list b: //input number & scores of student: //if number is 0,stop inputing. //1,98 //5,76 //0 //There are 4 records: //1 98 //3 78 //5 76 //7 88 //请按任意键继续. . .   //第二次输入：  //input list a: //input number & scores of student: //if number is 0,stop inputing. //5,66 //9,88 //0 //input list b: //input number & scores of student: //if number is 0,stop inputing. //1,76 //2,85 //0 //运行到这里就出错了。

user: user-1
content: 引用 6 楼 Alonzo_11 的回复:那该怎么办呢 能自行解决吗 @user-1 建议先从分析清楚函数struct student* insert(struct student* ah, struct student* bh)里的判断逻辑开始，然后就你发现的问题，想想问题出在哪儿，试着去修改下，改错了也没关系，再把代码复制粘贴回去就是了，加油

user: user-0
content: 那该怎么办呢 能自行解决吗 @user-1

user: user-1
content: 引用 4 楼 Alonzo_11 的回复:引用//运行结果：   //input list a: //input number & scores of student: //if number is 0,stop inputing. //1,60 //4,80 //0 //input list b: //input number & scores of student: //if number is 0,stop inputing. //3,90 //6,70 //0 //There are 4 records: //1 60 //3 90 //4 80 //6 70 //请按任意键继续. . .  某些测试数据没有排序 对的，这个函数struct student* insert(struct student* ah, struct student* bh)，存在漏洞，有待完善，加油

user: user-1
content: 改了没大问题了，可以运行，小细节上有待完善。供参考：//#include <bits/stdc++.h> #include <iostream.h> using namespace std; #define LEN sizeof(struct student)  struct  student {     long num;     int score;     struct student* next; };  struct student lista, listb; int n, sum = 0;  int main() {     struct student* creat(void);     struct student* insert(struct student*, struct student*);     void print(struct student*);     struct student* ahead, * bhead, * abh;     printf("input list a:\n");     ahead = creat();     sum = sum + n;     printf("input list b:\n");     bhead = creat();     sum = sum + n;     abh = insert(ahead, bhead);     print(abh);      system("pause");     return 0; }  struct student* creat(void) {     struct student* p1, * p2, * head;     n = 0;     p1 = p2 = (struct student*)malloc(LEN);     printf("input number & scores of student:\n");     printf("if number is 0,stop inputing.\n");     scanf("%ld,%d", &p1->num, &p1->score);//这里的输入格式是带','号的，英文半角     head = NULL;     while (p1->num != 0)     {         n = n + 1;         if (n == 1)             head = p2; //head = p1;         else             p2->next = p1;         p2 = p1;         p1 = (struct student*)malloc(LEN);         scanf("%ld,%d", &p1->num, &p1->score);//这里的输入格式是带','号的，英文半角     }     p2->next = NULL;     return(head); }  struct student* insert(struct student* ah, struct student* bh) {     struct student* pa1, * pa2, * pb1, * pb2;     pa2 = pa1 = ah;     pb2 = pb1 = bh;     do     {         while ((pb1->num > pa1->num) && (pa1->next != NULL))  //!= nullptr))         {             pa2 = pa1;             pa1 = pa1->next;         }         if (pb1->num <= pa1->num)         {             if (ah == pa1)                 ah = pb1;             else                 pa2->next = pb1;             pb1 = pb1->next;             pb2->next = pa1;             pa2 = pb2;             pb2 = pb1;         }     } while ((pa1->next != NULL) || (pa1 == NULL && pb1 != NULL));     if ((pb1 != NULL) && (pb1->num > pa1->num) && (pa1->next == NULL))         pa1->next = pb1;     return(ah); }  void print(struct student* head) {     struct student* p;     printf("There are %d records:  \n", sum);     p = head;     if (p != NULL)         do         {             printf("%ld %d\n", p->num, p->score);             p = p->next;         } while (p != NULL); }   //运行结果：  //input list a: //input number & scores of student: //if number is 0,stop inputing. //1,60 //4,80 //0 //input list b: //input number & scores of student: //if number is 0,stop inputing. //3,90 //6,70 //0 //There are 4 records: //1 60 //3 90 //4 80 //6 70 //请按任意键继续. . .

user: user-0
content: 改了还是一样的情况o

user: user-1
content: while ((pb1->num > pa1->num) && (pa1->next != nullptr))改为：while ((pb1->num > pa1->num) && (pa1->next != NULL ))