Программа не моя , а друга. Просил помочь, а я прошу Вас знатоков С++, помочь в нелегком деле, нужно описать каждую функцию(сделать подпись) Спасибо заранее огромное всем кто поможет!!!
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
| #include<stdio.h>
#include<locale.h>
#include<conio.h>
#include <stdlib.h>
const int STACK_RESET_SIZE = 4;
const int STACKS_STORED = 20;
const int STACKS_STORE_SIZE = STACK_RESET_SIZE * STACKS_STORED;
const int START_INDEX = STACKS_STORE_SIZE / 2 - STACK_RESET_SIZE / 2;
const int END_INDEX = STACKS_STORE_SIZE / 2 + STACK_RESET_SIZE / 2;
int storedArray[STACKS_STORE_SIZE] = {0};
int arrayStartIndex = STACKS_STORE_SIZE / 2;
class stackelem //создается 1класс
{
public: //открытые функции и переменные класса
int data;
stackelem *next;
};
class stack //создается второй класс
{
public: //открытые функции и переменные 2 класса/стек
stackelem *last;
stackelem *cursor;
stack();
~stack();
void put(int d);
void puut(int d);
int get();
int getcursor();
bool isempty();
void print();
int see();
void left();
void right();
void bput(int d);
bool relocate();
int size();
};
void stack::right() //перемещение вправо
{
if (last == 0) return;
if(cursor->next==0)
cursor=cursor;
else
cursor=cursor->next;
}
void stack::left() //перемещение влево
{
if (last == 0) return;
stackelem *f=last;
if(cursor!=last) {
while(f->next!=cursor)
f=f->next;
cursor=f;
}
}
stack::stack()
{
last=0;
}
bool stack::isempty()
{
return !last;
}
int stack::see()
{
return isempty() ? 0 : last->data;
}
void stack::put(int d)// описание функции put
{
stackelem *newel;
newel=new stackelem;
newel->data=d;
if (last==0)
{
last=newel;
cursor = last;
last->next=0;
}
else
{
newel->next=last;
last=newel;
cursor = last;
}
}
void stack::puut(int d)// описание функции puut
{
stackelem *newel;
newel=new stackelem;
newel->data=d;
if(last ==0)
put(d);
else
{
newel->next=cursor->next;
cursor->next=newel;
}
}
void stack::bput(int d) // описание функции bput
{
stackelem *newel;
stackelem *p=last;
newel=new stackelem;
newel->data=d;
if(last ==0)
put(d);
else
{
if(cursor==last)
{
put(d); cursor=cursor->next;
}
else
{
while(p->next!=cursor)
p=p->next;
newel->next=p->next;
p->next=newel;
}
}
}
int stack::get()
{
if (last==0)
return 0;
stackelem *del=last;
int d=last->data;
last=last->next;
delete del;
return d;
}
int stack::getcursor()
{
while(last!=0)
{
stackelem *del=last;
int d=cursor->data;
if(cursor==last)
{
del=cursor;
last=cursor->next;
cursor=last;
delete del;
}
else
{
while(del->next!=cursor)
del=del->next;
cursor=del;
del=cursor->next;
cursor->next=cursor->next->next;
delete del;
}
return d;
}
return 0;
}
stack::~stack()
{
while (last!=0)
get();
}
void stack::print() // описание функции print
{
if (last==0)
{
printf("Список пуст\n");
return;
}
stackelem *pr=last;
while(pr!=0)
{
if(pr==cursor)
printf("(%i) ",pr->data);
else
printf("%i ", pr->data);
pr=pr->next;
}
printf("\n");
}
bool stack::relocate() {
if (arrayStartIndex == 0) return false;
arrayStartIndex -= STACK_RESET_SIZE / 2;
for (int i = arrayStartIndex; i < START_INDEX; i++)
storedArray[i] = storedArray[i + STACK_RESET_SIZE / 2];
for (int i = END_INDEX; i < STACKS_STORE_SIZE - arrayStartIndex; i++)
storedArray[i] = storedArray[i - STACK_RESET_SIZE / 2];
for (int i = START_INDEX; i < END_INDEX; i++)
storedArray[i] = get();
return true;
}
int stack::size() {
if (!last) return 0;
int result = 1;
stackelem* ptr = last;
while (ptr = ptr->next)
result++;
return result;
}
void watchArray() { // описание функции watchArray
printf("Массив:\n");
for (int i = arrayStartIndex; i < STACKS_STORE_SIZE - arrayStartIndex; i++)
printf("%i ", storedArray[i]);
printf("\n");
system("pause");
}
int main() // описаание основной программы
{
setlocale(LC_ALL, "RUS");
stack s;
int z;
for(;;)
{
system("cls");
s.print();
printf("Добро пожаловать\n1)Вправо\n2)Влево\n3)Добавить после выделенного элемента\n4)Добавить перед выделенным элементом\n5)Удалить\n6)посмотреть массив\n7)Выход\n");
scanf("%i", &z);
if(z==1)
s.right();
if(z==2)
s.left();
if ((z == 3 || z == 4) && s.size() == STACK_RESET_SIZE) {
printf(s.relocate() ? "Стек успешно перемещён\n" : "Не удалось переместить стек\n");
}
if(z==3)
{
int d;
printf("Введите элемент: ");
scanf("%i", &d);
s.puut(d);
}
if(z==4)
{
int d;
printf("Введите элемент: ");
scanf("%i", &d);
s.bput(d);
}
if(z==5)
s.getcursor();
if (z==6)
watchArray();
if(z==7)
exit(1);
}
} |
|