Created
December 4, 2012 19:36
-
-
Save hauleth/4207841 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <stdlib.h> | |
using namespace std; | |
void menu() | |
{ | |
cout << "\tKOLKO I KRZYZYK"<<endl; | |
cout << "Wcisnij:\n1. Wprowadz graczy\n2. GRA\nx. Koniec\n\n"; | |
cout << "\tSTRUKTURA"<<endl; | |
cout << "Wcisnij:\n" | |
"3. Dodac nowy element\n" | |
"4. Wyswietlic liste\n" | |
"5. Usunac wybrany element\n" | |
"6. Wyszukac parametr\n" | |
"7. Usuwanie wszystkich elementow o ocenie z informatyki wynoszacej 2\n" | |
"x. Koniec\n\n"; | |
} | |
struct SStudent{ | |
char imie[20]; | |
char nazwisko[20]; | |
char indeks[7]; | |
int ocena; | |
SStudent *next; | |
}; | |
SStudent *root=NULL; | |
SStudent* StworzStudenta(void) | |
{ | |
SStudent *pStudent=new SStudent; | |
pStudent->next=NULL; | |
cout << "Podaj numer indeksu"<<endl; | |
cin >>pStudent->indeks; | |
cout << "Podaj imie"<<endl; | |
cin >> pStudent->imie; | |
cout << "Podaj nazwisko"<<endl; | |
cin >> pStudent->nazwisko; | |
cout << "Podaj ocene z informatyki"<<endl; | |
cin >> pStudent->ocena; | |
return pStudent; | |
} | |
void WyswietlStudenta(SStudent*pStudent) | |
{ | |
cout << "\nNumer indeksu: " << pStudent->indeks | |
<< "\nImie: " << pStudent->imie | |
<< "\nNazwisko: " << pStudent->nazwisko | |
<< "\nOcena z informatyki: " << pStudent->ocena; | |
} | |
SStudent * DodajStudenta(SStudent *nowyStudent) | |
{ | |
nowyStudent->next = root; | |
return root = nowyStudent; | |
} | |
SStudent *Ostatni() | |
{ | |
if (root == NULL) | |
return NULL; | |
SStudent* last = root; | |
while (last->next != NULL) | |
last = last->next; | |
return last; | |
} | |
SStudent * DodajStudentaNaKoniec(SStudent *nowyStudent) | |
{ | |
SStudent *last = Ostatni(); | |
if (last == NULL) | |
return root = nowyStudent; | |
return last->next = nowyStudent; | |
} | |
void WyswietlListeStudentow(SStudent*root) | |
{ | |
SStudent *aktualny = root; | |
while (aktualny !=NULL) | |
{ | |
WyswietlStudenta(aktualny); | |
aktualny=aktualny->next; | |
} | |
} | |
void UsuwanieElementu(int n) | |
{ | |
if (n==0) | |
{ | |
SStudent *usun = root->next; | |
delete root; | |
root=usun; | |
} | |
n--; | |
SStudent *usun = root; | |
while (usun!=NULL && n--) | |
usun=usun->next; | |
if (usun!=NULL) | |
{ | |
SStudent *remove = usun->next->next; | |
delete usun->next; | |
usun->next=remove; | |
} | |
} | |
int SzukajPoInf(int ocena) | |
{ | |
SStudent *szukaj=root; | |
int i=0; | |
while (szukaj!=NULL && szukaj->ocena !=ocena) | |
{ | |
i++; | |
szukaj = szukaj->next; | |
} | |
return i; | |
} | |
void UsuwanieZ2() | |
{ | |
while (root != NULL && root->ocena < 3) { | |
SStudent *tmp = root->next; | |
delete root; | |
root = tmp; | |
} | |
SStudent *usun = root; | |
while (usun != NULL) | |
{ | |
while (usun->next != NULL && usun->next->ocena < 3) | |
{ | |
SStudent *pomoc = usun->next->next; | |
delete usun->next; | |
usun->next=pomoc; | |
} | |
usun=usun->next; | |
} | |
} | |
int main() | |
{ | |
char wybor; | |
do | |
{ | |
menu(); | |
cin >> wybor; | |
cout << '\n'; | |
switch(wybor) | |
{ | |
case '2': | |
case '1': | |
break; | |
case '3': | |
{ | |
DodajStudentaNaKoniec(StworzStudenta()); | |
break; | |
} | |
case '4': | |
{ | |
WyswietlListeStudentow(root); | |
break; | |
} | |
case '5': | |
{ | |
int x; | |
cout << "Podaj numer elementu do usuniecia"; | |
cin >> x; | |
UsuwanieElementu(x); | |
break; | |
} | |
case '6': | |
{ | |
char ocena; | |
cout << "Podaj ocene by wyszukac\n"; | |
cin >> ocena; | |
cout << SzukajPoInf(ocena) << '\n'; | |
break; | |
} | |
case '7': | |
{ | |
cout << "Usuwanie wszystkich elementow o ocenie z informatyki wynoszacej 2\n\n"; | |
UsuwanieZ2(); | |
break; | |
} | |
case 'x': | |
case 'X': | |
return 0; | |
default : | |
cout << "BLAD" << endl; | |
} | |
cout << '\n'; | |
} | |
while(wybor !='x' && wybor !='X'); | |
while (root != NULL) { | |
SStudent * tmp = root->next; | |
delete root; | |
root = tmp; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment