-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperasyon.cpp
372 lines (310 loc) · 11 KB
/
operasyon.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
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
//
// operasyon.cpp
// algo 1.001
//
// Created by Can Babaoğlu on 8.10.2017.
// Copyright © 2017 Can Babaoğlu. All rights reserved.
//
#include "main.h"
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <vector>
using namespace std;
bool CardManager::OpenTheFile(const char argi[]){
string a = argi;
//cout<<"acmanin ici" <<a;
OcakTasi = fopen(argi, "r+" );
if(!OcakTasi){
if(!(OcakTasi = fopen(argi, "w+" ))){
return false;
}
}
return true;
}
void CardManager::ReadFromFile(vector<Cards> &a){
Cards tutucu; // tek tek çek içe
fseek(OcakTasi, 0, SEEK_SET); // al başa
while(!feof(OcakTasi)){
fscanf(OcakTasi,"%[^\t]\t%[^\t]\t%[^\t]\t%[^\t]\t%[^\t]\t%d",tutucu.Name,tutucu.Class,tutucu.Rarity,tutucu.Set,tutucu.Type,&tutucu.Cost);
//cout<<tutucu.Name<<tutucu.Class<<tutucu.Rarity<<tutucu.Set<<tutucu.Type<<tutucu.Cost;
// OKUYOR!!!
//if(feof(OcakTasi)) break; gerek yok
a.push_back(tutucu);// ver vektöre
}
}
void CardManager::PrintTheVector(vector<Cards> &a ){ // test edebilmek için yazılmış bir fonksiyon
for(int i=0;i<a.size();i++){
cout<<a[i].Name<<"-"<<a[i].Class<<"-"<<a[i].Rarity<<"-"<<a[i].Set<<"-"<<a[i].Type<<"-"<<a[i].Cost<<endl;
}
}
void CardManager::WriteToFile(vector<Cards> &a, long int n, const char argi[]){
FILE *OcakTasi1;
OcakTasi1 = fopen(argi, "w+");
fseek(OcakTasi1,0,SEEK_SET);
for(int i=0;i<n;i++)//tek tek al˝p aralara tab atarak dosyaya yaz.
{
fprintf(OcakTasi1,"%s\t%s\t%s\t%s\t%s\t%d",a[i].Name,a[i].Class,a[i].Rarity,a[i].Set,a[i].Type,a[i].Cost);
}
fclose(OcakTasi1);
}
void CardManager::FullInsertionSort(vector<Cards> &a, long int n){
int i,j;
Cards key;
// = operatorünü overload edip yapamadım olmadı nedense :)
for (j = 2; j <n; j++) // burda class a göre sort
{
strcpy(key.Name, a[j].Name);
strcpy(key.Class, a[j].Class);
strcpy(key.Rarity, a[j].Rarity);
strcpy(key.Set, a[j].Set);
strcpy(key.Type, a[j].Type);
key.Cost=a[j].Cost;
i = j-1;
while (i >= 0 && (strcmp(a[i].Class,key.Class)>=0) )
{
strcpy(a[i+1].Name,a[i].Name);
strcpy(a[i+1].Class,a[i].Class);
strcpy(a[i+1].Rarity,a[i].Rarity);
strcpy(a[i+1].Set,a[i].Set);
strcpy(a[i+1].Type,a[i].Type);
a[i+1].Cost = a[i].Cost;
i = i-1;
}
strcpy(a[i+1].Name, key.Name);
strcpy(a[i+1].Class,key.Class);
strcpy(a[i+1].Rarity, key.Rarity);
strcpy(a[i+1].Set, key.Set);
strcpy(a[i+1].Type, key.Type);
a[i+1].Cost=key.Cost;
}
for (j = 2; j <n; j++) // burda eğer clasları aynıysa cost a göre sort
{
strcpy(key.Name, a[j].Name);
strcpy(key.Class, a[j].Class);
strcpy(key.Rarity, a[j].Rarity);
strcpy(key.Set, a[j].Set);
strcpy(key.Type, a[j].Type);
key.Cost=a[j].Cost;
i = j-1;
while (i >= 0 && (strcmp(a[i].Class,key.Class)==0) && ((a[i].Cost)>=(key.Cost)))
{
strcpy(a[i+1].Name,a[i].Name);
strcpy(a[i+1].Class,a[i].Class);
strcpy(a[i+1].Rarity,a[i].Rarity);
strcpy(a[i+1].Set,a[i].Set);
strcpy(a[i+1].Type,a[i].Type);
a[i+1].Cost = a[i].Cost;
i = i-1;
}
strcpy(a[i+1].Name, key.Name);
strcpy(a[i+1].Class,key.Class);
strcpy(a[i+1].Rarity, key.Rarity);
strcpy(a[i+1].Set, key.Set);
strcpy(a[i+1].Type, key.Type);
a[i+1].Cost=key.Cost;
}
for (j = 2; j <n; j++) // burda eğer clasları aynıysa cost a göre sort
{
strcpy(key.Name, a[j].Name);
strcpy(key.Class, a[j].Class);
strcpy(key.Rarity, a[j].Rarity);
strcpy(key.Set, a[j].Set);
strcpy(key.Type, a[j].Type);
key.Cost=a[j].Cost;
i = j-1;
while (i >= 0 && (strcmp(a[i].Class,key.Class)==0) && (a[i].Cost==key.Cost) && (strcmp(a[i].Name,key.Name)>=0))
{
strcpy(a[i+1].Name,a[i].Name);
strcpy(a[i+1].Class,a[i].Class);
strcpy(a[i+1].Rarity,a[i].Rarity);
strcpy(a[i+1].Set,a[i].Set);
strcpy(a[i+1].Type,a[i].Type);
a[i+1].Cost = a[i].Cost;
i = i-1;
}
strcpy(a[i+1].Name, key.Name);
strcpy(a[i+1].Class,key.Class);
strcpy(a[i+1].Rarity, key.Rarity);
strcpy(a[i+1].Set, key.Set);
strcpy(a[i+1].Type, key.Type);
a[i+1].Cost=key.Cost;
}
}
void CardManager::FilterInsertionSort(vector<Cards> &a, long int n){
int i,j;
Cards key;
// = operatorünü overload edip yapamadım olmadı nedense :)
for (j = 2; j <n; j++) // burda class a göre sort
{
strcpy(key.Name, a[j].Name);
strcpy(key.Class, a[j].Class);
strcpy(key.Rarity, a[j].Rarity);
strcpy(key.Set, a[j].Set);
strcpy(key.Type, a[j].Type);
key.Cost=a[j].Cost;
i = j-1;
while (i >= 0 && (strcmp(a[i].Type,key.Type)>=0) )
{
strcpy(a[i+1].Name,a[i].Name);
strcpy(a[i+1].Class,a[i].Class);
strcpy(a[i+1].Rarity,a[i].Rarity);
strcpy(a[i+1].Set,a[i].Set);
strcpy(a[i+1].Type,a[i].Type);
a[i+1].Cost = a[i].Cost;
i = i-1;
}
strcpy(a[i+1].Name, key.Name);
strcpy(a[i+1].Class,key.Class);
strcpy(a[i+1].Rarity, key.Rarity);
strcpy(a[i+1].Set, key.Set);
strcpy(a[i+1].Type, key.Type);
a[i+1].Cost=key.Cost;
}
}
void CardManager::FilterMerge(vector<Cards>& a, long int p , long int q, long int r){
long int i,j;
long int n1 = (q-p)+1; // sol dizim
long int n2 = (r-q); // sağ dizim
vector<Cards> Left;
vector<Cards> Right;
for(i=0; i<n1; i++){
Left.push_back(a[p+i]);
}
for(j=0; j<n2; j++){
Right.push_back(a[q+j+1]);
}
////////////////////////////
Cards sonsuzluk;
strcpy(sonsuzluk.Name, "{"); // ASCII tablosunda harflerden sonra gelen bi sembol tilde
strcpy(sonsuzluk.Class, "{");
strcpy(sonsuzluk.Rarity, "{");
strcpy(sonsuzluk.Set, "{");
strcpy(sonsuzluk.Type, "{");
sonsuzluk.Cost = 99999; // 999 çok sonsuz bi sayı
Left.push_back(sonsuzluk);
Right.push_back(sonsuzluk);
i=0;
j=0;
for(long int k=p; k<=r; k++){
if(strcmp(Left[i].Type,Right[j].Type)<=0){ //if(Left[i] <= Right[j]){
strcpy(a[k].Name,Left[i].Name);
strcpy(a[k].Class,Left[i].Class);
strcpy(a[k].Rarity,Left[i].Rarity);
strcpy(a[k].Set,Left[i].Set);
strcpy(a[k].Type,Left[i].Type);
a[k].Cost = Left[i].Cost;
i++;
}
else{
strcpy(a[k].Name,Right[j].Name);
strcpy(a[k].Class,Right[j].Class);
strcpy(a[k].Rarity,Right[j].Rarity);
strcpy(a[k].Set,Right[j].Set);
strcpy(a[k].Type,Right[j].Type);
a[k].Cost = Right[j].Cost;
j++;
}
}
}
void CardManager::FullMerge(vector<Cards>& a, long int p , long int q, long int r){
long int i,j;
long int n1 = (q-p)+1; // sol dizim
long int n2 = (r-q); // sağ dizim
vector<Cards> Left;
vector<Cards> Right;
for(i=0; i<n1; i++){
Left.push_back(a[p+i]);
}
for(j=0; j<n2; j++){
Right.push_back(a[q+j+1]);
}
Cards sonsuzluk;
strcpy(sonsuzluk.Name, "~~~"); // ASCII tablosunda harflerden sonra gelen bi sembol tilde
strcpy(sonsuzluk.Class, "~~~");
strcpy(sonsuzluk.Rarity, "~~~");
strcpy(sonsuzluk.Set, "~~~");
strcpy(sonsuzluk.Type, "~~~");
sonsuzluk.Cost = 99999; // 999 çok sonsuz bi sayı
//Left.push_back(sonsuzluk);
//Right.push_back(sonsuzluk);
i=0;
j=0;
for(long int k=p; k<=r; k++){
if(strcmp(Left[i].Class,Right[j].Class)<0 ){ //Class a göre sırala
strcpy(a[k].Name,Left[i].Name);
strcpy(a[k].Class,Left[i].Class);
strcpy(a[k].Rarity,Left[i].Rarity);
strcpy(a[k].Set,Left[i].Set);
strcpy(a[k].Type,Left[i].Type);
a[k].Cost = Left[i].Cost;
i++;
}
else if( strcmp(Left[i].Class,Right[j].Class )==0){
if(Left[i].Cost < Right[j].Cost ){
strcpy(a[k].Name,Left[i].Name);
strcpy(a[k].Class,Left[i].Class);
strcpy(a[k].Rarity,Left[i].Rarity);
strcpy(a[k].Set,Left[i].Set);
strcpy(a[k].Type,Left[i].Type);
a[k].Cost = Left[i].Cost;
i++;
}
else if (Left[i].Cost == Right[j].Cost){
if(strcmp(Left[i].Name,Right[j].Name )<=0){
strcpy(a[k].Name,Left[i].Name);
strcpy(a[k].Class,Left[i].Class);
strcpy(a[k].Rarity,Left[i].Rarity);
strcpy(a[k].Set,Left[i].Set);
strcpy(a[k].Type,Left[i].Type);
a[k].Cost = Left[i].Cost;
i++;
}
else{
strcpy(a[k].Name,Right[j].Name);
strcpy(a[k].Class,Right[j].Class);
strcpy(a[k].Rarity,Right[j].Rarity);
strcpy(a[k].Set,Right[j].Set);
strcpy(a[k].Type,Right[j].Type);
a[k].Cost = Right[j].Cost;
j++;
}
}
else{
strcpy(a[k].Name,Right[j].Name);
strcpy(a[k].Class,Right[j].Class);
strcpy(a[k].Rarity,Right[j].Rarity);
strcpy(a[k].Set,Right[j].Set);
strcpy(a[k].Type,Right[j].Type);
a[k].Cost = Right[j].Cost;
j++;
}
}
else{
strcpy(a[k].Name,Right[j].Name);
strcpy(a[k].Class,Right[j].Class);
strcpy(a[k].Rarity,Right[j].Rarity);
strcpy(a[k].Set,Right[j].Set);
strcpy(a[k].Type,Right[j].Type);
a[k].Cost = Right[j].Cost;
j++;
}
}
}
void CardManager::FilterMergeSort(vector<Cards>&a , long int p , long int r){
if(p < r){
long int q = (p/2) + (r/2);
FilterMergeSort(a, p, q); //sol yanım
FilterMergeSort(a, q+1, r); // sağ yanım
FilterMerge(a, p, q, r);
}
}
void CardManager::FullMergeSort(vector<Cards>&a , long int p , long int r){
if(p < r){
long int q = (p/2) + (r/2);
FullMergeSort(a, p, q); //sol yanım
FullMergeSort(a, q+1, r); // sağ yanım
FullMerge(a, p, q, r);
}
}