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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;

//#include "lista_polje.h"
#include "lista_pokazivac.h"

igra igr;

int test_podaci(lista*);
int t_unos(lista*, int, int, string, string, int);

int generator(lista *GL, int n){
	int brGen;
	bool postoji;
	do{
		postoji = false;
		brGen = n*1000 + rand()%1000;
		for(element t=FirstL(GL); t!=EndL(GL); t=NextL(t, GL))
			if(brGen == RetreiveL(t, GL).sifra)
				postoji = true;
	}while(postoji);
	return brGen;
}

int unos_igre(lista *GL){	
	int z, pz;
	cout << "Unos nove igre\n";
	cout << "-------------------\n";
	do{
		cout << "Odaberite zanr:\n";
		cout << "-------------------\n";
		cout << "1. Action\n";
		cout << "2. RPG\n";
		cout << "3. Sport\n";
		cout << "4. Strategy\n";
		cout << "5. Ostalo\n";
		cout << "-------------------\n";
		cout << "Vas izbor: ";
		cin >> z;
	}while(z<1 || z>5);
	cout << "-------------------\n";
	do{
		switch(z){
			case 1:
				igr.zanr = "Action";
				cout << "Odaberite podzanr:\n"; 
				cout << "-------------------\n";
				cout << "1. FPS\n";
				cout << "2. TPS\n";
				cout << "3. MOBA\n";
				cout << "4. Tactical\n";
				cout << "5. Ostalo\n";
				cout << "-------------------\n";
				cout << "Vas izbor: ";
				cin >> pz;
				switch(pz){
					case 1: igr.podzanr = "FPS"; break;
					case 2: igr.podzanr = "TPS"; break;
					case 3: igr.podzanr = "MOBA"; break;
					case 4: igr.podzanr = "Tactical"; break;
					case 5: cin.ignore(); cout << "Unesite podzanr: "; getline(cin, igr.podzanr); break;
				}
				break;
			case 2:
				igr.zanr = "RPG";
				cout << "Odaberite podzanr:\n";
				cout << "-------------------\n"; 
				cout << "1. Action RPG\n";
				cout << "2. MMORPG\n";
				cout << "3. Western RPG\n";
				cout << "4. Tactical RPG\n";
				cout << "5. Ostalo\n";
				cout << "-------------------\n";
				cout << "Vas izbor: ";
				cin >> pz;
				switch(pz){
					case 1: igr.podzanr = "Action RPG"; break;
					case 2: igr.podzanr = "MMORPG"; break;
					case 3: igr.podzanr = "Western RPG"; break;
					case 4: igr.podzanr = "Tactical RPG"; break;
					case 5: cin.ignore(); cout << "Unesite podzanr: "; getline(cin, igr.podzanr); break;
				}
				break;
			case 3:
				igr.zanr = "Sport";
				cout << "Odaberite podzanr:\n"; 
				cout << "-------------------\n";
				cout << "1. Racing\n";
				cout << "2. Competitive\n";
				cout << "3. Sports game\n";
				cout << "5. Ostalo\n";
				cout << "-------------------\n";
				cout << "Vas izbor: ";
				cin >> pz;
				switch(pz){
					case 1: igr.podzanr = "Racing"; break;
					case 2: igr.podzanr = "Competitive"; break;
					case 3: igr.podzanr = "Sports game"; break;
					case 5: cin.ignore(); cout << "Unesite podzanr: "; getline(cin, igr.podzanr); break;
				}
				break;
			case 4:
				igr.zanr = "Strategy";
				cout << "Odaberite podzanr:\n"; 
				cout << "-------------------\n";
				cout << "1. Artillery\n";
				cout << "2. RTS\n";
				cout << "3. Tower defense\n";
				cout << "4. Wargame\n";
				cout << "5. Ostalo\n";
				cout << "-------------------\n";
				cout << "Vas izbor: ";
				cin >> pz;
				switch(pz){
					case 1: igr.podzanr = "Artillery"; break;
					case 2: igr.podzanr = "RTS"; break;
					case 3: igr.podzanr = "Tower defense"; break;
					case 4: igr.podzanr = "Wargame"; break;
					case 5: cin.ignore(); cout << "Unesite podzanr: "; getline(cin,igr.podzanr); break;
				}
				break;
			case 5:
				cin.ignore();
				cout << "Unesite zanr: ";
				getline(cin, igr.zanr);
				cout << "Unesite podzanr: ";
				getline(cin, igr.podzanr);
				pz=5;			
				break;
		}
	}while(pz<1 || pz>5);
	z *= 10;
	z += pz;
	if(pz!=5) cin.ignore();
	cout << "-------------------\n";
	cout << "Naziv: ";
	getline(cin, igr.naziv);
	cout << "Proizvodac: ";
	getline(cin, igr.proizvodac);
	do{
		cout << "PEGI (3, 7, 12, 16 ili 18): ";
		cin >> igr.PEGI;
	}while(igr.PEGI!=3 && igr.PEGI!=7 && igr.PEGI!=12 && igr.PEGI!=16 && igr.PEGI!=18);
	igr.sifra = generator(GL, z);
	cout << "Sifra: " << igr.sifra << endl;
	
	if(InsertL(igr, EndL(GL), GL))
		return 1;
	else
		return 0;	
}

element trazi(int k, lista *GL){
	element trazeni = FirstL(GL);
	for(int i=0; i<k; i++)
		trazeni = NextL(trazeni, GL);
	return trazeni;
}

void merge(lista *GL, lista *pom, int lijevo, int pivot, int desno){
	int i=lijevo, j=pivot+1, k=lijevo;
	while(i<=pivot && j<=desno){
		element it = trazi(i, GL);
		element jt = trazi(j, GL);
		if(RetreiveL(it, GL).sifra <= RetreiveL(jt, GL).sifra){
			InsertL(RetreiveL(it, GL), trazi(k, pom), pom);
			i++;
			k++;
		}
		else{
			InsertL(RetreiveL(jt, GL), trazi(k, pom), pom);
			j++;
			k++;
		}
	}
	if(i>pivot){
		while(j<=desno){
			element jt = trazi(j, GL);
			InsertL(RetreiveL(jt, GL), trazi(k, pom), pom);
			j++;
			k++;
		}
	}
	else{
		while(i<=pivot){
			element it = trazi(i, GL);
			InsertL(RetreiveL(it, GL), trazi(k, pom), pom);
			i++;
			k++;
		}
	}

	element t=trazi(lijevo, pom);
	element t2=trazi(lijevo, GL);
	for(int i=lijevo; i<k; i++, t=NextL(t, pom), t2=NextL(t2, GL)){
		igra a = RetreiveL(t, pom);
		DeleteL(t2, GL);
		InsertL(a, t2, GL);
	}
}

void merge_sort(lista *GL, lista *pom, int lijevo, int desno){
	if(lijevo < desno){
		int middle = (lijevo+desno)/2;

		merge_sort(GL, pom, lijevo, middle);
		merge_sort(GL, pom, middle+1, desno);
		merge(GL, pom, lijevo, middle, desno);
	}
}

void ispis_igara(lista *GL, lista *pom){
	int broj=0;
	for(element t=FirstL(GL); t!=EndL(GL); t=NextL(t, GL))
		broj++;
	
	if(!broj){
		cout << "Lista je prazna!\n\n";
		return;
	}
	cout << "Broj igara u listi: " << broj << endl;
	
	merge_sort(GL, pom, 0, broj-1);
		
	element t=FirstL(GL);
	igra ispisi;
	cout << "\nIspis svih igara\n";
	cout << "------------------------------------\n";
	for(t; t!=EndL(GL); t=NextL(t, GL)){
		ispisi = RetreiveL(t, GL);
		cout << "Sifra: " << ispisi.sifra << endl;
		cout << "Naziv: " << ispisi.naziv << endl;
		cout << "Zanr: " << ispisi.zanr << endl;
		cout << "PEGI: " << ispisi.PEGI << endl;
		cout << "------------------------------------\n";
		
	}	
}

int BS_strategy(lista *GL, int lijevo, int desno){
	int mid = (lijevo+desno)/2;
	while(((RetreiveL(trazi(mid, GL), GL).sifra)/10000 != 4) && (lijevo <= desno)){
		if((RetreiveL(trazi(mid, GL), GL).sifra)/10000 > 4)
			desno = mid-1;
		else
			lijevo = mid+1;
		mid = (lijevo+desno)/2;
	}
	if(lijevo <= desno) return mid;
	return -1;
}

int strategy(lista *GL){
	igra ispisi;
	int a, broj=0, brS=0;

	for(element t=FirstL(GL); t!=EndL(GL); t=NextL(t, GL))
		broj++;
	
	if(!broj) return broj;
		
	a = BS_strategy(GL, 0, broj-1);
	if(a == -1) return a;
	cout << "Ispis svih strateskih igara\n";
	cout << "------------------------------------\n";
	int des = a+1;
	for(a; (a>=0) && (RetreiveL(trazi(a, GL), GL).sifra)/10000 == 4; a--){
		ispisi = RetreiveL(trazi(a, GL), GL);
		cout << "Sifra: " << ispisi.sifra << endl;
		cout << "Naziv: " << ispisi.naziv << endl;
		cout << "Zanr: " << ispisi.zanr << endl;
		cout << "PEGI: " << ispisi.PEGI << endl;
		cout << "------------------------------------\n";
		brS++;
	}

	for(des; (des<broj) && (RetreiveL(trazi(des, GL), GL).sifra)/10000 == 4; des++){
		ispisi = RetreiveL(trazi(des, GL), GL);
		cout << "Sifra: " << ispisi.sifra << endl;
		cout << "Naziv: " << ispisi.naziv << endl;
		cout << "Zanr: " << ispisi.zanr << endl;
		cout << "PEGI: " << ispisi.PEGI << endl;
		cout << "------------------------------------\n";
		brS++;
	}
	return brS;
}

int brisi_sifra(lista* GL, int sifra){
	for(element t=FirstL(GL); t!=EndL(GL); t=NextL(t, GL)){
		if(sifra == RetreiveL(t, GL).sifra){
			DeleteL(t, GL);
			return 1;
		}
	}
	return 0;
}

int brisi_pegi(lista* GL, int pg){
	bool obrisano = false;
	element t=FirstL(GL);
	while(t!=EndL(GL)){
		if(pg == RetreiveL(t, GL).PEGI){
			DeleteL(t, GL);
			obrisano = true;
			continue;
		}
		t=NextL(t, GL);
	}
	if(obrisano) return 1;
	return 0;
}

int main (){
	int q, b, p, brs, izbor;
	lista GL;
	InitL(&GL);
	lista pom;
	InitL(&pom);
	do{
		cout << "----------------------------------------------------\n";
		cout << "\t\tI Z B O R N I K\n";
		cout << "----------------------------------------------------\n";
		cout << "1. Unos nove igre\n";
		cout << "2. Sortiranje igara merge sortom i ispis\n";
		cout << "3. Pretraga strateskih igara binarnim pretrazivanjem\n";
		cout << "4. Brisanje igara po sifri\n";
		cout << "5. Brisanje igara po PEGI oznaci\n";
		cout << "8. Unos testnih podataka\n";
		cout << "9. Izlaz\n";
		cout << "----------------------------------------------------\n";
		cout << "Vas izbor: ";
		cin >> izbor;
		switch(izbor){
			case 1:
				system("cls");
				if(unos_igre(&GL)){
					cout << "\nIgra je uspjesno unesena!\n\n";
					break;
				}
				cout << "\nIgra nije unesena!\n\n";
				break;
				
			case 2:
				system("cls");
				ispis_igara(&GL, &pom);
				break;
				
			case 3:
				system("cls");
				brs = strategy(&GL);
				if(!brs){
					cout << "Lista je prazna!\n\n";
					break;
				}
				if(brs == -1){
					cout << "\nNema strateskih igara u listi!\n\n";
					break;
				}
				cout << "\nUkupan broj strateskih igara: " << brs << endl << endl;
				break;
				
			case 4:
				system("cls");
				cout << "Brisanje elemenata po sifri\n";
				cout << "------------------------------------\n";
				cout << "Unesite sifru: ";
				cin >> b;
				if(brisi_sifra(&GL, b)){
					cout << "\nIgra je uspjesno obrisana!\n\n";
					break;
				}
				cout << "\nNe postoji igra s tom sifrom!\n\n";
				break;
				
			case 5:
				system("cls");
				cout << "Brisanje elemenata po PEGI oznaci\n";
				cout << "------------------------------------\n";
				cout << "Unesite PEGI(3, 7, 12, 16, 18): ";
				cin >> p;
				if(brisi_pegi(&GL, p)){
					cout << "\nIgre su uspjesno obrisane!\n\n";
					break;
				}
				cout << "\nNe postoji igra s tom PEGI oznakom!\n\n";
				break;
				
			case 8:
				system("cls");
				q = test_podaci(&GL);
				cout << "Uspjesno je uneseno " << q << " igara.\n\n";
				break;
				
			case 9:
				cout << "Izlazim.\n";
				break;
			default:
				cout << "Pogresan unos.\n\n";
		}
	}while(izbor!=9);
	system("pause");
	return 0;
}

int t_unos(lista *GL, int z, int pz, string naz, string pro, int pg){
	int s = z*10;
	s += pz;
	igr.sifra = generator(GL, s);
	igr.naziv = naz;
	igr.proizvodac = pro;
	igr.PEGI = pg;
	switch(z){
		case 1:
			igr.zanr = "Action";
			switch(pz){
				case 1: igr.podzanr = "FPS"; break;
				case 2: igr.podzanr = "TPS"; break;
			}
			break;
		case 2:
			igr.zanr = "RPG";
			switch(pz){
				case 1: igr.podzanr = "Action RPG"; break;
				case 2: igr.podzanr = "MMORPG"; break;
			}
			break;
		case 4:
			igr.zanr = "Strategy";
			switch(pz){
				case 2: igr.podzanr = "RTS"; break;
				case 3: igr.podzanr = "Tower defense"; break;
			}
			break;
	}
	if(InsertL(igr, EndL(GL), GL))
		return 1;
	else
		return 0;
}

int test_podaci(lista* GL){
	int c=0;
	//1 Action
	//1.1 FPS
	c += t_unos(GL, 1, 1, "Call of Duty", "Activision", 16);
	c += t_unos(GL, 1, 1, "Doom 3", "Ativicion", 18);
	c += t_unos(GL, 1, 1, "Wolfenstein 3D", "ZeniMax", 12);
	
	//1.2 TPS
	c += t_unos(GL, 1, 2, "SOCOM: U.S. Navy SEALs", "Activision", 16);
	c += t_unos(GL, 1, 2, "Lost Planet", "Capcom", 12);
	c += t_unos(GL, 1, 2, "Max Payne", "Remedy Entertainment", 16);
		
	//2 RPG
	//2.1 ActionRPG
	c += t_unos(GL, 2, 1, "Borderlands: The Pre-sequel", "Take2", 18);
	c += t_unos(GL, 2, 1, "Divine Divinity", "Empire Interactive", 7);
	c += t_unos(GL, 2, 1, "FATE", "Wild Studios", 12);
	
	//2.2 MMORPG
	c += t_unos(GL, 2, 2, "Planet Calypso", "Mindark", 16);
	c += t_unos(GL, 2, 2, "Neverwinter", "Arc Games", 16);
	c += t_unos(GL, 2, 2, "Silkroad", "Joymax", 16);	
	
	//4 Strategy
	//4.2 RTS
	c += t_unos(GL, 4, 2, "Company of Heroes", "SEGA", 18);
	c += t_unos(GL, 4, 2, "Empire: Total War", "SEGA", 16);
	c += t_unos(GL, 4, 2, "Warcraft III", "Blizzard", 12);
	
	//4.3 Tower defense
	c += t_unos(GL, 4, 3, "Plants vs Zombies", "EA Swiss Sarl", 7);
	c += t_unos(GL, 4, 3, "McDroid", "Elefantopia", 16);
	c += t_unos(GL, 4, 3, "Savage Moon", "Fluffy Logic", 7);
	
	return c;
}