hi every one i am having problem in accessing my 2d linked list..i am able to get a function in a 1d linked list but this is quite confusing.please if some one could give me a basic algorithm which i could work with i would appreciate it...thanks the function i need help with is get data().this function returns true if data retrival is succesful else it returns false.
here is my code for the linked list fucntion

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

using namespace std;

template <class T> //default constructor
base_tail = NULL;
}
template <class T> //destructor
NODE< NODE<T>* > * cur_row;
NODE< T > * cell;

NODE<T> * cur_row_tail;

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

}

}

template <class T>
NODE< NODE<T>* > * pnode = new NODE< NODE<T>* >;
pnode->nData = NULL;

}

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>

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();

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;

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

return true;
}

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

// need help here

return bsuccess;
}

template <class T>
NODE < NODE<T>* > * cur_row = NULL;
NODE<int> *cell = NULL;

cout<<get_data(0, 0, data);
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>
}``````
2
Contributors
1
2
Views
8 Years
Discussion Span
Last Post by Ancient Dragon

The 2d linked lists I have worked with in the past is really nothing more than a linked list within a linked list. Something like this:

I have not done it using templates.

``````struct node
{
struct node* next;
void* data;