Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. void Liste::supprimeIemeElement(unsigned int x)  // my function wants to delete the Xth  element of a chained list
  2. {
  3.   Cellule * temp1; // My chained list is composed by "Cellule"
  4.   temp1 = prem;   // prem is the first "Cellule" of my chained list  
  5.   unsigned int i;
  6.   i = 1;
  7.         while (temp1 != NULL && i <= x)
  8.         {
  9.             if (x == i)
  10.             {
  11.                 if (temp1->suivant == NULL)
  12.                 {
  13.                     supprimerQueue();   // function that delete the last elemnt of my chained list; works
  14.                 }
  15.                 else if (temp1->precedent == NULL)
  16.                 {
  17.                     supprimerTete (); // function that delete the first element of my chained list; also works
  18.                 }
  19.                 else
  20.                 {
  21.                     temp1->suivant->precedent = temp1->precedent;  // "precedent" is for the next element
  22.                     temp1->precedent->suivant = temp1->suivant;   // "suivant" is for the next one
  23.                 }
  24.                 delete temp1;   // <--- here i want to delete the #i elemnt of my list but i think theres a problem here
  25.             }
  26.             else
  27.             {
  28.                 temp1 = temp1->suivant;
  29.             }
  30.             i = i + 1;
  31.         }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement