Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Binary Tree Problem

Empfohlene Antworten

Veröffentlicht

Hallo

Ich habe versucht ein Programm für einen Binärbaum zu schreiben, jedoch stürzt mir das Programm beim Eingeben/Ausgeben mancher Folgen Elementen immer ab mit einem Fehler in der ntdll.dll

Z.b wenn ich 3 neue Nodes eingebe : 9 , 1 , 10

Ich vermute der Fehler liegt wohl in der insertNode Funktion.

Habe hier mal den Code :

Ich bedanke mich jetzt schonmal.

#include<stdio.h>

#include<stdlib.h>


struct Node

{

int element;


struct Node *left,*right;

}*root;

typedef struct Node *node;

typedef int ElementType;


node insertNode(ElementType, node);

void display(node, int);

void main()

{

    char ch;

    ElementType a;



    while(1)       // Hauptmenü mit Auswahlmöglichkeiten

    {

        printf("\n<e>... Element Einfuegen\n<a>... Sortierte Ausgabe\n<x>... Programm beenden\n\nWarte auf Auswahl : \n----------------------------\n");

        scanf("%s",&ch);

        switch(ch)

            {


                case 'e':

                        printf("\nGeben Sie ein Element ein : ");

                        scanf("%d", &a);

                        root = insertNode(a, root);

                        break;


                case 'a':

                        if(root==NULL)

                        printf("\n Baum ist leer!");

                        else

                        display(root, 1);

                        break;


                case 'x':

                        exit(0);


                default:

                        printf("ERROR ! Unzulaessige Eingabe");


            }

    }

}

//---------------------------------------------------------------------------------- INSERT


node insertNode(ElementType x,node t)

{

    if(t==NULL)

    {

        t = (node)malloc(sizeof(node));

        t->element = x;

        t->left = t->right = NULL;

    }

    else

    {

        if(x > t->element)

            t->left = insertNode(x, t->left);


        else if(x < t->element)

            t->right = insertNode(x, t->right);

    }

    return t;

}

//---------------------------------------------------------------------------------- AUSGABE


void display(node t,int level)

{

    int i;

    if(t)

    {


        display(t->right, level+1);

        printf("\n");

        for(i=0;i<level;i++)


        printf(" ");

        printf("%d", t->element);

        display(t->left, level+1);

    }

} 

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.