Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct lista
- {
- int liczba;
- lista *next;
- };
- int main()
- {
- lista *poczatek;
- lista *temp;
- lista *nastepna;
- int ile;
- cout<<"podaj ilosc liczb"<<endl;
- cin>>ile;
- poczatek = new lista;
- poczatek->next = NULL;
- cin>>poczatek->liczba;
- temp = poczatek;
- for(int i=1; i<ile; i++)
- {
- nastepna = new lista;
- temp->next = nastepna;
- cin>>nastepna->liczba;
- nastepna->next = NULL;
- temp = nastepna;
- }
- //wywietla
- temp = poczatek;
- while(temp)
- {
- cout<<temp->liczba<<endl;
- temp = temp->next;
- }
- //usuwa
- while(poczatek!=NULL)
- {
- temp = poczatek;
- poczatek = poczatek->next;
- delete temp;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement