Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7889613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:08:38+00:00 2026-06-03T06:08:38+00:00

I try to create BFS like of tree. I made the tree and queue

  • 0

I try to create BFS like of tree. I made the tree and queue the child.

I’ve wrote the code in here https://github.com/cengek/CKDatastruct.

But strangely, when my friends who use Windows and MinGW to compile it it return error. It doesn’t happen in OSX and and Linux.

My friend said it become error when I used malloc.

I don’t know where the specific code that does the error but I think it’s in here

this is the part where I put the child of tree into the queue

   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);
    }

and in here for adding the childs into the queue so I can process it. It does the print of the child.

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++;

}

I think it is the ordinary code of queue and tree.

Honestly I don’t know where the exact part because it does strangely different in every operating system, i’ve try to compile it in ideone and give the correct result as this http://ideone.com/vVNOe

My friend said the error from windows is like this

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

Does every operating system do the different malloc? Or is it just my code that do the error?

Best Regards
giripp

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T06:08:40+00:00Added an answer on June 3, 2026 at 6:08 am

    I’m not sure if this is the cause of your problem or not, but it might be. In add() you allocate a new simpul and place that pointer into a paket, but then you immediately overwrite that pointer with the one passed as an argument to add():

    baru->paket.s = (simpul *) malloc(sizeof(simpul));
    baru->paket.s = s;
    

    But I’m not sure.


    Also, your makeTree() function needs to initialize the child member of the root node:

    baru->child=NULL;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is a sample code in java: try { /* create connection */ Connection
I want to try create something like Zend's Server Pagecache. What I want to
snippet from The Server code : public void run() { try { // Create
I have the following code: try { //Create connection SQLiteConnection conn = DBConnection.OpenDB(); //Verify
I try create two moving object from one class. I want to control they
I'll try create a controler in towerjs, but I have an error while updating
I to try create my first javascript app with backbone.js And I found strange
I have specific troubles when I try create node. From context menu everything gona
I try to create an EAR with the maven assembly plugin but I got
I try to create a hibernate mapping for an oracle database. The datebase is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.