Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- #include <stdlib.h>
- #include <stdio.h>
- using namespace std;
- struct Osoba
- {
- char nazwa[20];
- struct Osoba *next=NULL;
- };
- int opcja=0;
- char pierwszy[20];
- char imie[20];
- int ilosc=0;
- int i=0;
- int main()
- {
- struct Osoba *first = NULL;
- struct Osoba *current = NULL;
- struct Osoba *temp = NULL;
- struct Osoba *temp2 = NULL;
- cout << "Podaj imie pierwszej osoby na liscie: ";
- cin >> pierwszy;
- //dodawanie pierwszej osoby
- first = new struct Osoba;
- strcpy(first->nazwa,pierwszy);
- current=first;
- while(true)
- {
- system("cls");
- cout << "1. Dodaj osobe do listy" <<endl;
- cout << "2. Wyswietl osoby na liscie" <<endl;
- cout << "3. Usun osobe z listy" <<endl<<endl;
- cin >> opcja;
- if(opcja==1)
- {
- system("cls");
- //dodawanie kolejnej osoby
- cout << "Podaj imie osoby, ktora chcesz dodac: ";
- cin >> imie;
- temp = new struct Osoba;
- strcpy(temp->nazwa,imie);
- current->next=temp;
- current=temp;
- }
- else if(opcja==2)
- {
- int i=1;
- system("cls");
- cout << "Lista:" << endl << endl;
- temp=first;
- while(temp!=NULL)
- {
- cout << temp->nazwa<<endl;
- temp=temp->next;
- }
- getchar();
- getchar();
- }
- else if(opcja==3)
- {
- system("cls");
- int u;
- cout << "Podaj numer osoby: ";
- cin >> u;
- temp=first;
- temp2=first;
- if(u==1)
- {
- first=first->next;
- delete temp;
- }
- else
- {
- for (int i=0;i<u-2;i++)
- {
- temp = temp->next;
- }
- temp2 = temp->next;
- temp->next = temp->next->next;
- delete temp2;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment