Advertisement
icatalin

3.6.2015 list dublu sterge insereseaza etc

Jun 3rd, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. //NETESTATE, UNELE NU MERG
  2.  
  3. #include <iostream>
  4. #include <fstream>
  5.  
  6. using namespace std;
  7.  
  8. ifstream f("date.in");
  9.  
  10. struct nod
  11. {
  12.     int info;
  13.     nod *st,*dr;
  14. };
  15.  
  16. nod *prim,*ultim;
  17.  
  18. void creare()
  19. {
  20.     nod *nou;
  21.     int x;
  22.    
  23.     while (f>>x)
  24.         if (prim==NULL)
  25.         {
  26.             prim=new nod;
  27.             prim->info=x;
  28.             prim->st=NULL;
  29.             ultim=prim;
  30.         }
  31.         else
  32.         {
  33.             nou=new nod;
  34.             nou->info=x;
  35.             nou->st=ultim;
  36.             ultim->dr=nou;
  37.             ultim=nou;
  38.         }
  39.         ultim->dr=NULL;
  40. }
  41.  
  42. void parcurgere_st()
  43. {
  44.     nod *p=ultim;
  45.     while (p)
  46.     {
  47.         if (p->info%2==0)
  48.         cout<<p->info<<" ";
  49.         p=p->st;
  50.     }
  51. }
  52.  
  53. void parcurgere_dr()
  54. {
  55.     nod *p=prim;
  56.     while (p)
  57.     {
  58.         if (p->info%2==1)
  59.             cout<<p->info<<" ";
  60.         p=p->dr;
  61.     }
  62. }
  63.  
  64. void inserare()
  65. {
  66.     nod *p=prim,nou;
  67.     while (p->info%2!=0&&p)
  68.         p=p->dr;
  69.    
  70.     if (p)
  71.     {
  72.         nou=new nod;
  73.         nou->info=p->info*p->info;
  74.         nou->dr=p->dr;
  75.         nou->st=p;
  76.         p->dr->st=nou;
  77.         p->dr=nou;
  78.     }
  79. }
  80.  
  81. void stergere()//stergeti ultimul nod cu inf. para
  82. {
  83.     nod *p=ultim,*q,*r;
  84.     while (p->info%2==1 && p )
  85.     p=p->st;
  86.    
  87.     q=p->dr;
  88.     r=p->st;
  89.     r->dr=q;
  90.     q->st=r;
  91.     delete p;
  92. }
  93.  
  94. int main()
  95. {
  96.    
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement