Advertisement
icatalin

liste recap

May 21st, 2015
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. ifstream f("date.in");
  7.  
  8. struct nod
  9. {
  10.     int info;
  11.     nod *urm;
  12. };
  13.  
  14. nod *prim;
  15.  
  16. void creare()
  17. {
  18.     int x;
  19.     nod *p,*nou;
  20.  
  21.     while (f>>x)
  22.         if (prim==NULL)
  23.     {
  24.         prim=new nod;
  25.         prim->info=x;
  26.         p=prim;
  27.     }
  28.     else
  29.     {
  30.         nou=new nod;
  31.         nou->info=x;
  32.         p->urm=nou;
  33.         p=nou;
  34.     }
  35.     p->urm=NULL;
  36. }
  37.  
  38. void afis()
  39. {
  40.     nod *p=prim;
  41.     while (p)
  42.     {
  43.         cout<<p->info<<" ";
  44.         p=p->urm;
  45.     }
  46. }
  47.  
  48. void inserare() // INSERARE DUPA primul nod
  49. {
  50.     nod *p=prim,*nou;
  51.     int x=69;
  52.  
  53.     while (p->info!=2 && p->urm)
  54.         p=p->urm;
  55.     nou=new nod;
  56.     nou->info=69;
  57.     nou->urm=p->urm;
  58.     p->urm=nou;
  59. }
  60.  
  61. void inserare2() // inserare dupa fiecare nod
  62. {
  63.     nod *p=prim,*nou;
  64.     int x=69;
  65.  
  66.     while (p->urm)
  67.     {
  68.         if (p->info%2==0)
  69.         {
  70.             nou=new nod;
  71.             nou->info=x;
  72.             nou->urm=p->urm;
  73.             p->urm=nou;
  74.         }
  75.         p=p->urm;
  76.     }
  77. }
  78.  
  79. void sterge() // sterge toata nodurile
  80. {
  81.     nod *p=prim,*r,*q;
  82.     while (p)
  83.     {
  84.         if (p->urm->info%2==0)
  85.         {q=p->urm;
  86.         r=p->urm->urm;
  87.         p->urm=r;
  88.         delete q;
  89.         }
  90.         p=p->urm;
  91.     }
  92. }
  93.  
  94.  
  95. void inserare_ultim()
  96. {
  97.   nod *p=prim,*nou;
  98.   while (p->urm)
  99.         p=p->urm;
  100.  
  101.   nou=new nod;
  102.   nou->info=69;
  103.   p->urm=nou;
  104.   nou->urm=NULL;
  105. }
  106.  
  107. void inserare_inainte()
  108. {
  109.     nod *p=prim,*nou;
  110.     nou=new nod;
  111.     nou->info=69;
  112.     nou->urm=prim;
  113.     prim=nou;
  114. }
  115.  
  116. void sterge_prim()
  117. {
  118.     nod *p=prim;
  119.     prim=prim->urm;
  120.     delete p;
  121. }
  122.  
  123. void sterge_ultim()
  124. {
  125.     nod *p=prim,*q;
  126.     while (p->urm->urm)
  127.         p=p->urm;
  128.     q=p->urm;
  129.     delete q;
  130.     p->urm=NULL;
  131. }
  132.  
  133. int main()
  134. {
  135.     creare();
  136.     sterge_ultim();
  137.     afis();
  138.     return 0;
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement