马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 英俊男孩建坤 于 2021-5-6 00:11 编辑 #include <iostream>
#include <stdlib.h>
using namespace std;
class Node{
public:
Node(); // initialization
void create(Node*); // randomly generate number
void print(Node*); // print link list
void reverse(); // reverse and pritn the lsit
Node *next; // pointer of next data
Node *prev; // point of last data
private:
int data;
};
void Node:: create(Node* a){
a->data = rand() % 100;
}
void Node::print(Node* a){
cout << a->data << endl;
}
int main(){
int num;
cout << "Input how long do you want to create the link list: ";
cin >> num;
Node *head1 = NULL;
for (int a = 0; a < num; a++){
Node *nodei = new Node();
nodei -> next = head1;
nodei->create(nodei);
head1 = nodei;
nodei->print(nodei);
}
return 0;
}
为啥我这代码用vs code一直报错 但是显示错误却又说没有问题?
|