Advertisement
Guest User

Untitled

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