Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2011
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1.         void Insert( int Data, unsigned int Position )
  2.         {
  3.             if ( Position > this -> Count )
  4.             {
  5.                 return;
  6.             }
  7.             ITEM * Item = NULL;
  8.             Item = new ITEM;
  9.             if ( Item == NULL )
  10.             {
  11.                 return;
  12.             }
  13.             Item -> Data = Data;
  14.             if ( this -> Count == 0 )
  15.             {
  16.                 Item -> Prev = NULL;
  17.                 Item -> Next = NULL;
  18.                 this -> First = Item;
  19.                 this -> Last = Item;
  20.                 this -> Active = Item;
  21.                 this -> Count ++;
  22.                 return;
  23.             }
  24.             if ( Position == 0 )
  25.             {              
  26.                 Item -> Prev = NULL;
  27.                 Item -> Next = this -> First;
  28.                 this -> First -> Prev = Item;
  29.                 this -> First = Item;
  30.                 this -> Count ++;
  31.                 return;
  32.             }
  33.             if ( Position == this -> Count )
  34.             {      
  35.                 Item -> Prev = this -> Last;
  36.                 Item -> Next = NULL;       
  37.                 this -> Last -> Next = Item;
  38.                 this -> Last = Item;
  39.                 this -> Count ++;
  40.                 return;
  41.             }
  42.             if ( Position == this -> Position )
  43.             {      
  44.                 Item -> Prev = this -> Active -> Prev;
  45.                 Item -> Next = this -> Active; 
  46.                 this -> Active -> Prev -> Next = Item; 
  47.                 this -> Active -> Prev = Item;
  48.                 this -> Last = Item;
  49.                 this -> Count ++;
  50.                 return;
  51.             }
  52.                
  53.         };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement