07.12.2010, 20:30. Просмотров 246. Ответов 0
Помогите найти ошибку в функции addList, при её вызове выскакивает ошибка accept violation.
C++ |
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
89
90
91
92
93
94
95
96
97
98
99
100
| #include<conio.h>
#include<iostream.h>
struct List
{
int value;
List* next;
List* prev;
};
void print(List* Lis){
List* cur = Lis;
List* first = Lis;
while(cur)
{
cout<<cur->value<<" ";
cur=cur->next;
if (cur==first){break;}
} cout<<"\n";
}
List* addList(List* a, List* b){
List* cur1 = a;
List* cur2 = b;
List* Lis=new List;
List* cur=Lis;
while(cur1)
{
cur->value=cur1->value;
cur=cur->next;
cur1=cur1->next;
}
while(cur2){
while(cur){
if(cur==cur2){
cur=cur->next;
cur2=cur2->next;
}
else{
cur->value=cur2->value;
cur=cur->next;
cur2=cur2->next;
}
}
}
return Lis;
}
List* create(int size)
{
List* Lis=new List;
List* cur=Lis;
int znach;
cout<<"Vvedite znachenie 1 elementa: ";
cin>>znach;
cur->value=znach;
for(int n=2;n<=size;n++)
{
cur->next=new List;
cout<<"Vvedite znachenie "<<n<<" elementa: ";
cin>>znach;
cur->next->value=znach;
cur->next->prev=cur;
cur=cur->next;
if(n==size)
{
cur->next=Lis;
Lis->prev=cur;
}
}
return Lis;
}
int main(){
List* List1;
List* List2;
int size1, size2;
cout<<"Vvedite razmer 1-go spiska: ";
cin>>size1;
if (size1==0){
cout<<"WRONG SIZE!!!";
getch();
}
List1=create(size1);
print(List1);
cout<<"Vvedite razmer 2-go spiska: ";
cin>>size2;
if (size2==0){
cout<<"WRONG SIZE!!!";
getch();
}
List2=create(size2);
print(List2);
List* List=addList(List1, List2);
cout<<"Obshiy spisok:\n";
print(List);
getch();
return 0;
} |
|