链表之语法基础课课堂代码
作者:
Coder_Li
,
2021-11-01 16:17:31
,
所有人可见
,
阅读 191
链表之语法基础课课堂代码
#include <iostream>
using namespace std;
struct Node
{
int val;
Node* next;
Node(int _val) : val(_val),next(NULL) {}
};
int main(){
Node* p = new Node (1);
Node* q = new Node (2);
Node* o = new Node (3);
p->next = q;
q->next = o;
Node* head = p;
//添加节点
Node* u = new Node (4);
u->next = head;
head = u;
//删除节点
head->next = head->next->next;
//链表遍历
for(Node* i = head; i ; i = i->next ){
cout << i->val << endl;
}
return 0;
}