-
Notifications
You must be signed in to change notification settings - Fork 7
/
2-3-18.cpp
88 lines (87 loc) · 1.47 KB
/
2-3-18.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include<iostream>
using namespace std;
typedef struct LNode{
int data;
// struct LNode* prior;
struct LNode* next;
}LNode, *LinkList;
void fun(LinkList &L1,LinkList &L2){
LinkList p=L1->next;
while(p->next!=L2){
if(p->next==L1){
p->next=L2->next;
}
p=p->next;
}
p->next=L1;
}
void fun_start(LinkList &L1,LinkList &L2){
fun(L1,L2);
}
//带头结点
void build_list(LinkList &L,LinkList &rear){
LinkList s;
int x=0;
L=(LinkList)malloc(sizeof(LNode));
L->next=NULL;
rear=L;
cin>>x;
while(x!=9999){
s=(LinkList)malloc(sizeof(LNode));
s->data=x;
rear->next=s;
/////双链表
// s->prior=rear;
/////
rear=s;
cin>>x;
}
//循环单链表
rear->next=L;
// L->prior=rear;
}
void print_list(LinkList &L){
//打印链表
//带头结点
LinkList s=L->next;
//while(s){
//双链表
while(s!=L){
cout<<s->data<<" ";
s=s->next;
}
cout<<endl;
LinkList p=L,tmp=L;
while(L!=tmp){
p=L;
L=L->next;
free(p);
}
}
void test(LinkList L,LinkList rear){
//测试前后
LinkList p=L->next;
cout<<"test1:front"<<endl;
while(p!=L){
cout<<p->data<<" ";
p=p->next;
}
cout<<endl<<"test2:rear"<<endl;
// while(rear!=L){
// cout<<rear->data<<" ";
// rear=rear->prior;
// }
cout<<endl;
}
////////////////////////////////////////////////////
int main(){
LinkList l1,l2,rear1,rear2;
build_list(l1,rear1);
build_list(l2,rear2);
fun_start(l1,l2);
// test(l1,rear1);
print_list(l1);
// print_list(l2);
return 0;
}
/////////////////////////////////////////////////