Advertisement
Guest User

Rezolvare subiect 1

a guest
Jan 28th, 2015
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. Struct Nod
  6. {
  7.     int cheie;
  8.     Nod *next;
  9. };
  10.  
  11. void adaug (Nod *& prim, int chnod)
  12. {
  13.     Nod *nou = new Nod;
  14.     nou->cheie = chnod;
  15.     if(prim == NULL)
  16.         nou->next = NULL;
  17.     else
  18.         nou->next = prim;
  19.     prim = nou;
  20. }
  21.  
  22. void sterg (Nod *& prim)
  23. {
  24.     if (prim == NULL)
  25.     {
  26.         cout<<"Lista vida";
  27.         return;
  28.     }
  29.     Nod *sters = prim;
  30.     sters->next = prim;
  31.     cout<<"Nodul sters "<<sters->cheie;
  32.     delete []sters;
  33. }
  34.  
  35. void parcurgere (Nod *prim)
  36. {
  37.     Nod *n = prim;
  38.     while (n!=NULL)
  39.     {
  40.         cout<<n->cheie;
  41.         n=n->next;
  42.     }
  43. }
  44.  
  45. // lista vida
  46. int listavida (Nod *prim)
  47. {
  48.     return prim==NULL;
  49. }
  50.  
  51. //lista plina
  52. int listaplina (Nod *prim,int limsup)
  53. {
  54.     int nr = 0;
  55.     Nod *n = prim;
  56.     while (n!=NULL)
  57.     {
  58.         nr++;
  59.         n=n->next;
  60.     }
  61.     if(nr==limsup)
  62.     {
  63.         cout<<"lista plina!";
  64.     }
  65.     return;
  66. }
  67.  
  68. void sterge_lista (Nod *&prim)
  69. {
  70.     while (prim!=NULL)
  71.     {
  72.         Nod *sters = prim;
  73.         prim=prim->next;
  74.         delete []sters;
  75.     }
  76.     prim=NULL;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement