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);
- void usunstudenta(int n);
- lista(){
- 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;
- 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;
- }
- }
- void lista::usunstudenta(int n){
- node* temp;
- temp=first;
- if(n==1) first=temp->next;
- else{
- int j=0;
- while(j+1<n) {
- temp=temp->next;
- j++;
- }
- if(temp->next->next==0) temp->next=0;
- else temp->next=temp->next->next;
- }
- }
- int main(){
- lista *baza=new lista;
- baza->dodajdolisty("Mariusz","Kowalski ",302432);
- baza->dodajdolisty("Tomasz","Nowak ",302433);
- baza->dodajdolisty("Andrzej","Golota ",323932);
- baza->usunstudenta(2);
- baza->wypiszliste();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement