小编Gre*_*t95的帖子

节点和链接列表出现问题

我有一个任务,我应该创建在双向链表中插入和删除节点的方法.但是我的C++有点生疏.我的前后指针出错了.

LinkedList.h

#ifndef LinkedList_h
#define LinkedList_h

#include <iostream>

using namespace std;

struct node {
    node * prev;
    int data;
    node * next;

};

class LinkedList {

private:
    //pointers to point to front and end of Linked List
    static node * front; //the error is coming from here
    static node * rear;  //the error is coming from here
public:
    static void insert_front(int data);
};
#endif
Run Code Online (Sandbox Code Playgroud)

LinkedList.cpp

#include "LinkedList.h"

//insert int to front
void LinkedList::insert_front(int data) {

    node *q = nullptr;
    //If …
Run Code Online (Sandbox Code Playgroud)

c++ static pointers private linked-list

4
推荐指数
2
解决办法
229
查看次数

标签 统计

c++ ×1

linked-list ×1

pointers ×1

private ×1

static ×1