noon of noob 2021-10-03 02:01 采纳率: 100%
浏览 103
已结题

VS历遍链表时读取访问权限冲突

先谢谢各位大佬
我搜了一些资料,知道是因为ptr是NULL才会出现这种情况(应该吧)但是不知道怎么改,求救
先上码


#include <iostream>
using namespace std;

typedef struct node {
    int xishu;
    int zhishu;
    node* next;
}node;
node *start1 = NULL;
node *start2 = NULL; 
node *create1(struct node *);
node *create2(struct node *);
node *add(struct node*);
node *display(struct node*);

int main()
{
    create1(start1);
    //create1(start2);
    display(start1);
}

node* create1(struct node* start)
{
    struct node* ptr, * new_node;
    int coefficient, index;
    /×art = new node;
    cout << "Enter 0 to end when you entering coefficient"<<endl;
    cout << "Enter the coefficient and index"<<endl;
    cin >> coefficient;
    cin >> index;
    //new_node = new node;
    
    while (coefficient != 0) {
        new_node = new node;
        new_node -> xishu = coefficient;
        new_node -> zhishu = index;
        if (start == NULL)
        {
            new_node -> next = NULL;
            start = new_node;
        }
        else {
            ptr = start;
            while (ptr->next != NULL)
                ptr = ptr->next;
            ptr->next = new_node;
            new_node->next = NULL;

        }
        cout << "Enter the coefficient and index" << endl;
        cin >> coefficient;
        cin >> index;
    }
    return start;


}

node *display(struct node *start) 
{
    struct node* ptr;
    ptr = start;
    while (ptr != NULL);
    {
        cout << ptr->xishu << "x^" << ptr->zhishu << endl;
        ptr->next = ptr;
    }
    return start;

}

问题如下

img

  • 写回答

3条回答 默认 最新

  • CSDN专家-link 2021-10-03 02:47
    关注

    报错的下一行改为ptr=ptr->next;循环的指针移动语句写反啦

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 10月11日
  • 已采纳回答 10月3日
  • 创建了问题 10月3日

悬赏问题

  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常
  • ¥15 关于风控系统,如何去选择