I'm not sure if it is working...though it compiles and runs.

I just want to know if what I have done is correct.

Here is the code that I've written:


Code:
template <class T>
bool linkedlist_2d<T>::get_data(int row, int col, T & data){
    bool bsuccess;

    NODE < NODE<T>* > * cur_row = NULL;
    NODE<int> *cell = NULL;            //node pointer variables
    
    cur_row = base_head; //cur_row points to base_head 
    
    int x = 0;
    while(x<row) //loop until row size
    {
        if(cur_row->pNext==NULL)
        {
             return false; //return false if next node is NULL
             }
             
        else cur_row = cur_row->pNext; //else point to next node
        
        x++;
    }
    cell = cur_row->nData; //make cell points first column node 
    int y = 0;
    while(y<col)//loop until col size 
    {
        if(cell->pNext==NULL)//return false if if next node is NULL
        {
             return false;
             }
             
        else cell = cell->pNext; //cell points to next node
        
        y++;
    }
    
     data=cell->nData;   //data is data of node
     bsuccess = true;   
                                            

    return bsuccess;    //return true    
}

template <class T>
bool linkedlist_2d<T>::update_data(int row, int col, const T data){
    bool bsuccess;

    NODE < NODE<T>* > * cur_row = NULL;
    NODE<int> *cell = NULL;            //node pointer variables
    
    cur_row = base_head; //cur_row points to base_head 
    
    int x = 0;
    while(x<row) //loop until row size
    {
        if(cur_row->pNext==NULL)
        {
             return false; //return false if next node is NULL
             }
             
        else cur_row = cur_row->pNext; //else point to next node
        
        x++;
    }
    cell = cur_row->nData; //make cell points first column node 
    int y = 0;
    while(y<col)//loop until col size 
    {
        if(cell->pNext==NULL)//return false if if next node is NULL
        {
             return false;
             }
             
        else cell = cell->pNext; //cell points to next node
        
        y++;
    }
    
     cell->nData = data;   //update cell data with data
     bsuccess = true;   
                                            

    return bsuccess;    //return true    


}

template <class T>
bool linkedlist_2d<T>::remove_data(int row, int col){
    bool bsuccess;

    NODE < NODE<T>* > * cur_row = NULL;
    NODE<int> *cell = NULL;
    NODE<int> *tail = NULL;
    NODE<T> * cur_row_tail;
    NODE<T> * cur_row_head;   //declare variables
    
    cur_row = base_head;
    
    int x = 0;
    while(x<row)
    {
        if(cur_row->pNext==NULL)
        {
             return false; //return false if next node is NULL
             }
             
        else cur_row = cur_row->pNext; //point to next node
        
        x++;
    }
    
    cell = cur_row->nData;
    cur_row_head = cell; //assign tail head after row loop
    int y = 0;
    while(y<col)
    {
        if(cell->pNext==NULL)
        {
             return false;
             }
             
        else cell = cell->pNext;
        
        y++;
    }
    tail = cell;
    
    if(tail->pNext==NULL)
    {
         cur_row_tail = tail; //if next node is NULL assign it as tail
     }                     
     else{
          while(tail->pNext!=NULL){
                tail = tail->pNext;    //else loop until next node is not NULL               
                }
          }           
          cur_row_tail = tail;//assign as tail
    
     RemoveNode(cell,&cur_row_head,&cur_row_tail); //call function to delete node  
     bsuccess = true;

    return bsuccess; //return true
        
}
I might probably be wrong...

Last edited by shabbir; 4Nov2009 at 19:28.. Reason: Code blocks