Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // -------------------------------------------------------
- #include <stdlib.h>
- #include <conio.h>
- #include <ctype.h>
- #include <process.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdbool.h>
- #include <time.h>
- #include <windows.h>
- // -------------------------------------------------------
- #define RED SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0*15+12)
- #define RESET SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0*15+15)
- // -------------------------------------------------------
- struct knoten
- {
- struct knoten *rechts;
- struct knoten *links;
- int wert;
- };
- // -------------------------------------------------------
- struct knoten *root = NULL; // Zeiger auf die Wurzel
- struct knoten *next = NULL; // Zeiger auf das rechte Element
- struct knoten *prev = NULL; // Zeiger auf das linke Element
- // -------------------------------------------------------
- int start(int);
- int addelement(int);
- int addroot(int);
- // -------------------------------------------------------
- int main()
- {
- system("CLS");
- int wurzel;
- printf("Geben Sie ihre Wurzel ein: ");
- scanf("%d",&wurzel);
- root = malloc(sizeof(struct knoten));
- root -> wert = wurzel;
- start(wurzel);
- }
- // -------------------------------------------------------
- int start(int wurzel)
- {
- int auswahl;
- printf("\n\n");
- printf("Was m\x94 \bchten Sie tun?\n");
- printf("--------------------\n");
- printf(" 1: Wurzel bestimmen!\n");
- printf(" 2: Element hinzuf\x81 \bgen!\n");
- printf("--------------------\n");
- printf("Wahl: ");
- scanf("%d",&auswahl);
- switch(auswahl)
- {
- case 1: addroot(wurzel); break;
- case 2: addelement(wurzel); start(wurzel); break;
- }
- }
- // -------------------------------------------------------
- int addroot(wurzel)
- {
- struct knoten *zeiger;
- printf("Geben Sie ihre Wurzel ein: ");
- scanf("%d",&wurzel);
- if(root == NULL)
- {
- root = malloc(sizeof(struct knoten));
- root -> wert = wurzel;
- }
- else
- {
- // root = malloc(sizeof(struct knoten));
- root -> wert = wurzel;
- }
- printf("\nIhre Wurzel hat nun den Wert: %d\n\n",root -> wert);
- start(wurzel);
- }
- // -------------------------------------------------------
- int addelement(int wurzel)
- {
- printf("\nIhre Wurzel hat nun den Wert: %d\n\n",root -> wert);
- struct knoten *zeiger;
- int element;
- printf("Geben Sie ihr Element ein: ");
- scanf("%d",&element);
- if(element < wurzel)
- {
- if(prev == NULL)
- {
- printf("CHECK 1\n");
- printf("Element[");RED;printf("L");RESET;printf("]");
- prev = malloc(sizeof(struct knoten));
- prev -> wert = element;
- }
- else
- {
- while(zeiger -> links != NULL && zeiger -> rechts != NULL)
- {
- if(element < prev -> wert)
- {
- printf("CHECK 2\n");
- printf("Element[");RED;printf("L");RESET;printf("]");
- prev = malloc(sizeof(struct knoten));
- prev -> wert = element;
- }
- else
- {
- printf("CHECK 3\n");
- printf("Element[");RED;printf("R");RESET;printf("]");
- next = malloc(sizeof(struct knoten));
- next -> wert = element;
- }
- zeiger = zeiger -> rechts;
- }
- }
- }
- else
- {
- if(next == NULL)
- {
- printf("CHECK 4\n");
- printf("Element[");RED;printf("R");RESET;printf("]");
- next = malloc(sizeof(struct knoten));
- next -> wert = element;
- }
- else
- {
- while(zeiger -> rechts != NULL && zeiger -> links != NULL)
- {
- if(element < prev -> wert)
- {
- printf("CHECK 5\n");
- printf("Element[");RED;printf("R");RESET;printf("]");
- prev = malloc(sizeof(struct knoten));
- prev -> wert = element;
- }
- else
- {
- printf("CHECK 6\n");
- printf("Element[");RED;printf("L");RESET;printf("]");
- next = malloc(sizeof(struct knoten));
- next -> wert = element;
- }
- zeiger = zeiger -> rechts;
- }
- }
- }
- }
- // -------------------------------------------------------
Add Comment
Please, Sign In to add comment