Advertisement
Guest User

Untitled

a guest
Oct 17th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.70 KB | None | 0 0
  1.  
  2. class list {
  3.     Noeud first;
  4. }
  5.  class Noeud {
  6.     Noeud next;
  7.     int val;
  8.  }
  9.  
  10.   list creerlist()
  11.   {
  12.     list L = new list();
  13.     L.first = null;
  14.     return L;
  15.   }
  16.  
  17.     void inversion (list l)
  18.     {
  19.         Noeud c = l.first;
  20.         Noeud max = l.first;
  21.         Noeud min = l.first;
  22.         while(c != null)
  23.         {
  24.             if (min.val > c.val)
  25.             {
  26.                 min = c;
  27.             }
  28.             if(max.val < c.val)
  29.             {
  30.                 max = c;
  31.             }
  32.             c = c.next;
  33.         }
  34.         int temp = min.val;
  35.         min.val = max.val;
  36.         max.val = temp;
  37.     }
  38.     void supprimer (Noeud n)
  39.     {
  40.         if(n.next != null)
  41.         {
  42.             n = n.next;
  43.         }
  44.         else
  45.         {
  46.             n = null;
  47.         }
  48.     }
  49.         void ajout_fin(list l, int e)
  50.     {
  51.         Noeud n = new Noeud();
  52.         n.val = e;
  53.         n.next = null;
  54.         if(l.first == null)
  55.         {
  56.             l.first = n;
  57.         } else
  58.         {
  59.             Noeud c = l.first;
  60.             Noeud p = c;
  61.             while(c != null)
  62.             {
  63.                 p = c;
  64.                 c = c.next;
  65.             }
  66.             p.next = n;
  67.         }
  68.     }
  69.     list effacerpair(list l)
  70.     {
  71.         list L2 = new list();
  72.         Noeud n = l.first;
  73.         while (n != null)
  74.         {
  75.             if(n.val % 2 == 1)
  76.             {
  77.                 ajout_fin(L2, n.val);
  78.             }
  79.             n = n.next;
  80.         }
  81.         return L2;
  82.     }
  83.     void affichage(list l)
  84.     {
  85.         Noeud c = l.first;
  86.         while (c != null)
  87.         {
  88.             print (c.val + " ");
  89.             c = c.next;
  90.         }
  91.         println("");
  92.     }
  93. void main(){
  94.     list L = creerlist();
  95.     list L2 = creerlist();
  96.     L.first = new Noeud();
  97.     L.first.val = 3;
  98.     L.first.next = new Noeud();
  99.     L.first.next.val = 8;
  100.     L.first.next.next = new Noeud();
  101.     L.first.next.next.val  = 7;
  102.     L.first.next.next.next = new Noeud();
  103.     L.first.next.next.next.val = 15;
  104.     list L3 = effacernoeud(L);
  105.     affichage(L3);
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement