Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- struct node{
- string imie;
- string nazwisko;
- int nr;
- node* next;
- node(){
- next=0;
- }
- };
- struct lista{
- node* first;
- void wypiszliste();
- void dodajdolisty(string im, string naz, int nr);
- bool usunstudenta(string name, string surname, int index);
- lista(){
- cout<<"im in semi constuctor"<<endl;
- first=0;
- }
- };
- void lista::dodajdolisty(string im, string naz, int nr){
- node* t = new node;
- t->imie=im;
- t->nazwisko=naz;
- t->nr=nr;
- if(first==0){
- first=t;
- t->next = NULL;
- }else{
- node *temp;
- temp=first;
- while(temp->next){
- temp=temp->next;
- }
- temp->next=t;
- t->next=0;
- }
- }
- void lista::wypiszliste(){
- node* temp;
- temp=first;
- while(temp){
- cout<<temp->imie;
- cout<<temp->nazwisko;
- cout<<temp->nr;
- cout<<endl;
- temp=temp->next;
- }
- }
- bool compareStudents(string name,string surname, int index, node* n){
- if(name.compare(n->imie) == 0 && surname.compare(n->nazwisko) == 0 && n->nr == index) return true;
- return false;
- }
- bool lista::usunstudenta(string name, string surname, int index){
- node* prev = first;
- node *current = first->next;
- while(current != NULL) {
- if(compareStudents(name,surname,index,current) == true) {
- break;
- }else {
- prev = current;
- current = current->next; // go to next value
- }
- }
- if(current == NULL) { // if we reached end of list or the list is empty
- cout << "Can't remove value: no match found.\n";
- return false;
- } else {
- cout << "Deleting: " << current << "\n";
- prev->next = current->next; // unlink the node you remove
- delete current; // delete the node
- }
- return true;
- }
- int main(){
- lista *baza=new lista;
- baza->dodajdolisty("Mariusz","Kowalski ",302432);
- baza->dodajdolisty("Tomasz","Nowak ",302433);
- baza->dodajdolisty("Andrzej","Golota ",323932);
- baza->wypiszliste();
- cout<<""<<endl;
- baza->usunstudenta("Tomasz","Nowak ",302433);
- baza->wypiszliste();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement