我尝试创建类似树的BFS。我制作了树并排起了小孩。Malloc中的操作系统之间的不同结果
我在这里写了代码https://github.com/cengek/CKDatastruct。
但奇怪的是,当我的朋友谁使用Windows和MinGW编译它会返回错误。它在OSX和Linux中不会发生。
我的朋友说,当我使用malloc时它变成了错误。
我不知道在哪里,做了错误的特定代码,但我认为这是在这里
这是我把树的孩子到队列
while (isEmpty(antrianNodes) != 1) {
//tampilkan isinya
printf("%c,", antrianNodes.first->paket.s->c);
simpul * now = antrianNodes.first->paket.s;
simpul * nodePertama = now;
//jika punya anak
//masukkan child dari node alamat di queue ke dalam queue sekarang
if(now->child != NULL){
simpul * nowchild = now->child;
//jika punya saudara
if(nowchild->sibling != NULL){
//looping memasukkan anak-anak
while (nowchild->sibling != now->child) {
add(&antrianNodes, nowchild);
nowchild = nowchild->sibling;
}
//masukkan yang terakhir
add(&antrianNodes, nowchild);
}else{
//tak punya saudara masukkan saja satu
add(&antrianNodes, nowchild);
}
}
del(&antrianNodes);
}
,并在部分在这里将孩子添加到队列中,以便我可以处理它。它打印了孩子的照片。
void add(queue *Q, simpul *s){
elemen * baru = (elemen *) malloc(sizeof(elemen));
baru->paket.s = (simpul *) malloc(sizeof(simpul));
baru->paket.s = s;
baru->next = NULL;
if(isEmpty(*Q) == 1){
(*Q).first = baru;
(*Q).last = baru;
}else{
(*Q).last->next = baru;
(*Q).last = baru;
}
(*Q).jumlahElemen++;
}
我认为这是队列和树的普通代码。
老实说,我不知道其确切的一部分,因为它在每个操作系统奇怪的不同,我已经尝试编译它ideone并给出正确的结果,因为这http://ideone.com/vVNOe
我的朋友说错误从Windows就是这样
Problem signature:
Problem Event Name: APPCRASH
Application Name: main.exe
Application Version: 0.0.0.0
Application Timestamp: 4fa665b6
Fault Module Name: main.exe
Fault Module Version: 0.0.0.0
Fault Module Timestamp: 4fa665b6
Exception Code: c0000005
Exception Offset: 000015e0
OS Version: 6.1.7601.2.1.0.256.48
Locale ID: 1033
Additional Information 1: 0a9e
Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
Additional Information 3: 0a9e
Additional Information 4: 0a9e372d3b4ad19135b953a78882e789
Read our privacy statement online:
http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409
If the online privacy statement is not available, please read our privacy statement offline:
C:\ WINDOWS \ SYSTEM32 \ EN-US \ erofflps.txt
是否每个操作系统做不同的malloc?还是只是我的代码做错误?
问候 giripp
究竟是什么错误? – Oleksi
你希望我们只是去阅读你的所有代码?为什么?把相关部分放在这里。 – littleadv
@Oleksi我的朋友做的截图,它说 MAIN.EXE已停止工作 Windows可以解决在网上查询的问题 – giripp