Advertisement
Guest User

Pb 3

a guest
Dec 11th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. struct nod
  4. {
  5.     int info;
  6.     nod *adr;
  7. };
  8. void citire( nod *&p, int n )
  9. {
  10.     int i;
  11.     nod *c;
  12.     if( p == NULL )
  13.         p = new nod;
  14.     cin >> p->info;
  15.     p->adr = NULL;
  16.     for ( i = 2 ; i <= n ; ++i )
  17.     {
  18.         c = new nod;
  19.         c->adr=p;
  20.         cin >> c->info;
  21.         p = c;
  22.     }
  23. }
  24. void addfst( nod *&p, int x )
  25. {
  26.     nod *a;
  27.     a = new nod;
  28.     a -> info = x;
  29.     a -> adr = p;
  30.     p = a;
  31. }
  32. void addlst( nod *p, int x )
  33. {
  34.     nod *a, *c;
  35.     a = new nod;
  36.     a -> info = x;
  37.     a -> adr = NULL;
  38.     c = p;
  39.     while( c->adr != NULL )
  40.         c = c->adr;
  41.     c -> adr = a;
  42. }
  43. void afisare( nod *p )
  44. {
  45.     while( p != NULL )
  46.     {
  47.         cout << p->info << " ";
  48.         p = p->adr;
  49.     }
  50. }
  51. int verif( nod *p )
  52. {
  53.     int flag = 1;
  54.     int minim = p->info;
  55.     while( p != NULL )
  56.     {
  57.         if( p->info < minim)
  58.             flag = 0;
  59.         p=p->adr;
  60.     }
  61.     return flag;
  62. }
  63. int main()
  64. {
  65.     int i, n;
  66.     nod *p;
  67.     cin >> n;
  68.     citire(p, n);
  69.     afisare(p);
  70.     cout << "\n";
  71.    cout << verif(p);
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement