我有一个代表图表的数组。我想将其转换为(i,j)
类型的i<j
的原型列表(因此没有双重数据)。到目前为止我有一个问题:
list[node]->..
不正确.. 到目前为止,这是我的代码,没有数组:
struct node {
public:
int number;
node* next;
};
class AdjList {
public:
void initialize (node* list);
void convert (bool** array, node* list);
void make (node*list, int number, int node);
private:
};
void AdjList::initialize (node* list) {
for (int i=0; i<10; i++) {
list[i]->next = NULL;
}
}
void AdjList::make(node* list, int num, int node) {
if (list[node]->next == NULL) {
node* New = new node*;
list->[node]->next = New;
New->next = NULL;
New->number = num;
}
else {
node* New = list[node];
while (New->next != NULL)
New = New->next;
node* New2 = new node*;
New->next = New2;
New2->number = num;
}
}
void AdjList::convert(bool** array, node* list) {
for (int i=0; i<10; i++) {
for (int j=i+1; j<10; j++) {
if (array[i][j] == true)
make(list, j, i);
}
}
}
int main () {
node* list[10];
}
答案 0 :(得分:0)
我会把它放在这里,也许对某人有帮助:
for (int i=0;i<bound;i++) {
for (int j=i+1;j<bound;j++) {
help = list[i];
if (Array[i][j] == true) {
help2 = new node;
if (help->next == NULL) {
help->next = help2;
help2->number = j;
help2->next = NULL;
}
else {
while (help->next != NULL)
help = help->next;
help->next = help2;
help2->next = NULL;
help2->number = j;
}
}
}
}
这就是我做到的。