#include <iostream>
using namespace std;
struct Node{
int i;
Node* next;
};
//创建
Node* creat(){
Node* head= new Node;
Node* cur = head;
while(1){
int node_a;
cout << "enter the number: ";
cin >> node_a;
if(node_a==0)break;
Node* p = new(Node);
p->i = node_a;
p->next = NULL;
cur->next = p;
cur = p;
}
return head;
}
void show(Node* p){
while(p != NULL){
cout << p->i<<"->" ;
p=p->next;
}
};
//插入
void in(Node* p, int n,int m){
Node * pre = p;
Node * cur = NULL;
while(pre->next != NULL){
cur = pre->next;
if(cur->i== m){
Node* t = new Node;
t->i = n;
t->next = cur;
pre->next = t;
pre = t;
}
pre = pre->next;
}
}
//翻转
void turn(Node* p){
Node* temp = NULL;
Node* t = p->next;
Node* k = t->next;
t->next = NULL;
while(k!= NULL){
temp =k->next;
k->next = t;
t = k;
k = temp;
}
p->next = t;
}
int main(){
Node* t = creat();
show(t->next);
cout << endl;
in(t,88,33);
show(t->next);
cout << endl;
turn(t);
show(t->next);
return 0;
}
链表
最新推荐文章于 2024-09-04 18:37:12 发布