So i guess the titles says it all i m trying to create dynamic structure of adjacency lists and i m having some errors since i m a little new in C anyone mind taking a look at it and tell me of any mistakes i might be doing
STRUCTURES
struct adjList //Data structure for an adjacency List
{
int pageNo; //stores the page number (unique)
int * link; //Stores a list of links to other pages
int noLinks; //No of links stored - If noLinks > 0 then node is a non-dangling node
// else if noLinks == 0 then its a dangling node
};
struct matrixList //Data structure for a Matrix
{
struct adjList ** matrix; //Array containing all the rows in our matrix
int noRows; //Total Number of rows in our matrix
int noColumns; //The total number of columns in our matrix
};
struct blockMatrix
{
struct matrixList *** block; //A2 dimensional Array of MatrixList
int noRows; //Total Number of rows in our matrix
int noColumns; //The total number of columns in our matrix
};
// BlockLoading.cpp : main project file.
#include "stdafx.h"
#include "PageRankFuncs.h"
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
using namespace System;
int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
blockMatrix * blocks = (blockMatrix *)malloc( sizeof(blockMatrix) );
//Create a 2 dimesional array of matrices
blocks->block = (matrixList ***)malloc( sizeof(matrixList **) );
blocks->noColumns = 5;
blocks->noRows=2;
for (int y = 0; y < blocks->noColumns; y++ )
{
blocks->block[y] = (matrixList **)malloc(sizeof(matrixList));
for ( int x = 0; x < blocks->noRows; x++)
{
blocks->block[y][x] = (matrixList *)malloc(sizeof(matrixList));
blocks->block[y][x]->matrix = (adjList **)malloc(BLOCK_SIZE * sizeof(adjList));
for (int z = 0; z < BLOCK_SIZE ; z++ )
{
blocks->block[y][x]->matrix[z] = (adjList *) malloc(sizeof(adjList));
blocks->block[y][x]->matrix[z]->link = (int *)malloc( sizeof(int) );
blocks->block[y][x]->matrix[z]->link[0] = 22;
}
}
}
for (int y = 0; y < blocks->noColumns; y++ )
{
for ( int x = 0; x < blocks->noRows; x++)
{
for (int z = 0; z < BLOCK_SIZE ; z++ )
{
if ( blocks->block[y][x]->matrix[z]->link != NULL )
free( blocks->block[y][x]->matrix[z]->link );
if ( blocks->block[y][x]->matrix[z] != NULL )
free( blocks->block[y][x]->matrix[z] );
}
if ( blocks->block[y][x]->matrix != NULL )
free( blocks->block[y][x]->matrix );
if ( blocks->block[y][x] != NULL )
free( blocks->block[y][x] );
}
if ( blocks->block[y] != NULL )
free( blocks->block[y] );
}
if ( blocks->block != NULL )
free( blocks->block );
if (blocks != NULL)
free( blocks);
return 0;
}