Hello,

So my problem is that I am supposed to write code in order to prove whether or not text in a file is topologically sorted correctly.
I have the algorithm on how to do this, but the specifications say that I should use an array of lists to keep track of each element's successors.
The thing is, I have no idea how to even start this.
I know how to declare an array of like ints, but not of lists.
Could I have some help?

Thanks

Member Avatar for tcstom

Hello,
I know how to declare an array of like ints, but not of lists.
Thanks

One way to do this is to create an array of pointers to arrays (lists)

The following code will create an array of pointers to arrays of unsigned ints, just replace the unsigned int part with whatever datatype your list contains:

unsigned int ** ProtocolReceiveBuffer;
int rows = 2;
int cols0 = 1500;
int cols1 = 1500;

ProtocolReceiveBuffer = malloc((rows)*sizeof(unsigned int*));

ProtocolReceiveBuffer[0] = malloc((cols0)*sizeof(unsigned int));
ProtocolReceiveBuffer[1] = malloc((cols1)*sizeof(unsigned int));
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.