@darknes
0 / 0 / 0
Регистрация: 22.09.2010
Сообщений: 11
|
|
|
17.04.2011, 02:40. Просмотров 1932. Ответов 5
Вот есть код все работает отлично но препод сказал что-бы при вводе элементов в список элементы сортировались вот к примеру 20 5 8 12 1 10 11 а должно быть 1 5 8 10 11 12 20 это задача про казнь она сделана тока надо сделать что-бы элементы сортировались плз помогите!!!
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
101
102
103
104
| #include "stdafx.h"
#include "iostream"
using namespace std;
struct Uzel
{
int value;
int num;
struct Uzel *next;
};
class List
{
private:
int n;
Uzel *head;
public:
List();
void Print_List();
void Add(int val);
Uzel *find(Uzel *nach,int index);
int Del_Element(int nach,int pos);
};
List::List()
{
head=NULL;
n=0;
}
Uzel *List::find(Uzel *nach,int index)
{
Uzel *first=nach;
for(int i=0;i<index;i++)
first=first->next;
return first;
}
void List::Add(int val)
{
Uzel *buf=new Uzel;
if(head==0)
{
head=buf;
buf->next=buf;
}
else
{
buf->next=head;
Uzel *pred=find(head,n-1);
pred->next=buf;
}
if (buf->value<val)
buf->value=val;
n++;
buf->num=n;
}
int List::Del_Element(int nach,int pos)
{
int i=0;
Uzel *buf=find(head,nach);
Uzel *pred=find(buf,pos-2);
Uzel *tek=find(buf,pos-1);
Uzel *sl=find(buf,pos);
if(tek==head)
head=sl;
pred->next=sl;
n--;
cout<<"Kaznili "<<tek->num<<" "<<tek->value<<endl;
delete tek;
return sl->num;
}
void List::Print_List()
{
int i=0;
Uzel *buf=head;
while(i<n)
{
cout<<"Ostalsya "<<buf->num<<" "<<buf->value<<";"<<endl;
buf=buf->next;
i++;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
List list;
int n;
cout<<"Vvedite kolvo chelovek"<<endl;
cin>>n;
int Item;
for(int i=0;i<n;i++)
{
cout<<"vvedite "<<i+1<<"-vo cheloveka"<<endl;;
cin>>Item;
list.Add(Item);
}
int nach;
cout<<"vvedite nachalo"<<endl;
cin>>nach;
int index;
cout<<"vvedite kashdogo kakogo nyshno kaznit"<<endl;
cin>>index;
for(int i=0;i<(n-1)/2;i++)
{
list.Del_Element(list.Del_Element(nach,index),index);
}
list.Print_List();
return 0;
} |
|
0
|