Advertisement
Dani_info

Tema 7.10.2019

Oct 6th, 2019
132
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct elev{
  6.     char nume[20];
  7.     int h;
  8.     elev *leg;
  9. }*v[100];
  10. int main()
  11. {
  12.     int n;
  13.     cout<<"n="; cin>>n;
  14.     for (int i=n-1; i>=0; i--){
  15.         v[i]=new elev;
  16.         cout<<"Elev: "<<i+1<<endl;
  17.         cout<<"Nume: "; cin>>v[i]->nume;
  18.         cout<<"H: "; cin>>v[i]->h;
  19.         if (i==(n-1)) v[i]->leg=NULL;
  20.         else v[i]->leg=v[i+1];
  21.     }
  22.     elev *p=new elev;
  23.     p=v[0];
  24.     while(p){
  25.         cout<<p->nume<<", "<<p->h<<endl;
  26.         p=p->leg;
  27.     }
  28.     //inserare 2/3
  29.     cout<<"Introdu datele elevului nou:"<<endl;
  30.     elev *elev_nou=new elev;
  31.     cout<<"Nume: "; cin>>elev_nou->nume;
  32.     cout<<"H: "; cin>>elev_nou->h;
  33.     v[1]->leg=elev_nou;
  34.     elev_nou->leg=v[2];
  35.     p=v[0];
  36.     cout<<"Lista dupa inserare:"<<endl;
  37.     while(p){
  38.         cout<<p->nume<<", "<<p->h<<endl;
  39.         p=p->leg;
  40.     }
  41.     //stergere penultimul nod
  42.     v[n-3]->leg=v[n-1];
  43.     delete v[n-2];
  44.     //dupa stergere:
  45.     p=v[0];
  46.     while(p){
  47.         cout<<p->nume<<", "<<p->h<<endl;
  48.         p=p->leg;
  49.     }
  50.     return 0;
  51. }
Advertisement
RAW Paste Data Copied
Advertisement