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

    //to do the missing implemetation

    return bsuccess;        
}
//this code is part of other linked_list_2d
template <class T>
bool linkedlist_2d<T>::update_data(int row, int col, const T data){
    bool bsuccess;

    //to do the missing implemetation

    return bsuccess;    
}

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

    //to do the missing implemetation

    return bsuccess;

}

Edited by Dani: Formatting fixed

Attachments
#include "linkedlist_2d.h"
#include <iostream>

using namespace std;

template <class T>
linkedlist_2d<T>::linkedlist_2d(){
    base_head = NULL;
    base_tail = NULL;
}
template <class T>
linkedlist_2d<T>::~linkedlist_2d(){
	NODE< NODE<T>* > * cur_row;
	NODE< T > * cell;

    NODE<T> * cur_row_head;
    NODE<T> * cur_row_tail;

	for (cur_row = base_head; cur_row != NULL; cur_row = cur_row->pNext){
		cur_row_head = cur_row->nData;
        for (cell = cur_row->nData; cell != NULL; cell = cell->pNext)
            cur_row_tail = cell;

		DeleteAllNodes(&cur_row_head, &cur_row_tail);
    }
		
	DeleteAllNodes(&base_head, &base_tail);
}

template <class T>
void linkedlist_2d<T>::append_row(){
    NODE< NODE<T>* > * pnode = new NODE< NODE<T>* >;
    pnode->nData = NULL;

    AppendNode(pnode, &base_head, &base_tail);
}

template <class T>
void linkedlist_2d<T>::append(int row, const T data){
    if (!append_col(row, data))
        cerr<<"Error appending data"<<endl;
}

template <class T>
bool linkedlist_2d<T>::append_col(int row, T data){  
    
    NODE < NODE<T>* > * cur_row = NULL;
    NODE <T> * last_col = NULL;
    NODE <T> * cell = new NODE<T>;

    if(row == 0 && base_head == NULL)
        append_row();     
    
    cur_row = base_head;

    if (cur_row == NULL)
        return false;

    //move to the specified row by checking existing rows
    int ilast_row;
    for(ilast_row = 1; ilast_row <= row; ilast_row++){
        cur_row = cur_row->pNext;
        if(cur_row == NULL){ 
            if (ilast_row == row){
                append_row(); 
                cur_row = base_tail;
            }    
            break;  
        }
    }

    if (cur_row == NULL)
        return false;
   
    //move to last column
    NODE<T> * cur_row_tail;
    NODE<T> * cur_row_head;

    cur_row_head = cur_row->nData;
    for (last_col = cur_row->nData; last_col != NULL; last_col = last_col->pNext){
        cur_row_tail = last_col;
    }
    cell->nData = data;            

    AppendNode(cell, &cur_row_head, &cur_row_tail);
	cur_row->nData = cur_row_head;

    return true;        
}


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

    //TODO...

	return bsuccess;		
}

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

    //TODO...

	return bsuccess;	
}

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

    //TODO...

	return bsuccess;
		
}

template <class T>
void linkedlist_2d<T>::print(){
    NODE < NODE<T>* > * cur_row = NULL;
    NODE<int> *cell = NULL;

    for (cur_row = base_head; cur_row != NULL; cur_row = cur_row->pNext){
        for (cell = cur_row->nData; cell != NULL; cell = cell->pNext)
            cout << cell->nData<<" ";
        cout<<endl;
    }
}

template <class T>
void linkedlist_2d<T>::erase(){
	this->~linkedlist_2d();
}
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by kesh1000
0

we cannot be of any help unless you show
some effort

start quote:

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

we cannot be of any help unless you show
some effort

    bool bsuccess;

    //to do the missing implemetation

    return bsuccess;        
}
//this code is part of other linked_list_2d
template <class T>
bool linkedlist_2d<T>::update_data(int row, int col, const T data){
    bool bsuccess;

    //to do the missing implemetation

    return bsuccess;    
}

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

    //to do the missing implemetation

    return bsuccess;

}

end quote.

Edited by mike_2000_17: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.