0

I am pretty new to programming and this question is probably very basic but;

I've been assigned with a homework which in one part asks me to;

Write a main program that reads commands from standard input and executes them. Every command corresponds to a function from the above modules/classes. Every time a list is created, it will be assigned a unique number. You can assume that at most 10 lists will be created by the input. The first list is assigned number 0 and the last one is assigned number at most 9

I already coded modules / classes (a linkedlist class, a linkedlist module, an array class and an array module) But I dont know how its even possible to create them automaticly and assign them a value, I dont even know where to start. I cannot use an array to store created lists because they belong to different variable types. Any tips is appreciated.

4

1 回答 1

0

您可以创建一个静态变量,每次创建列表时都会增加该变量,并使用此变量来识别创建的列表:

static int id = 0;

FunctionThatCreateList {
/* Your creation code */
SetId(id);
id++;
}

这样,每次创建列表时,都会设置它的 id 并且您确定它是唯一的

于 2013-08-03T14:05:13.657 回答