Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Laborübung19.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
- //
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #pragma warning (disable:4996)
- typedef int dataT;
- typedef struct node {
- struct node* left;
- struct node* right;
- dataT daten;
- }node_t;
- void init(node_t* root);
- void append(node_t* root, unsigned int LR, dataT data);
- void balance(node_t* root);
- void stringParsen(char *a, char**ptr[10]);
- int state[4][10] = {
- {2,1,1,1,2,1,1,1,2,3},
- {1,1,1,1,1,1,1,1,1,1},
- {2,1,1,1,2,1,1,1,2,3},
- {2,1,1,1,2,1,1,1,2,1}};
- char *cmd[10] = { "ST", "SD" ,"SG" ,"GT", "GD","GG","St","Sd","Sg","SF" };
- int main()
- {
- //NR1
- /*
- node_t tree;
- init(&tree);
- tree.daten = 5;
- append(&tree, 1, 8);
- append(&tree, 0, 10);
- append(tree.left, 1, 7);
- append(tree.left, 0, 3);
- append(tree.left->left, 0, 1);
- balance(&tree);
- */
- //NR2
- /*
- char a[2];
- int s = 0;
- int control = 0;
- while (1) {
- control = 0;
- printf("Zustand: S%d\n", s);
- scanf(" %s", a);
- for (int i = 0; i < 10; i++) {
- if (!strcmp(a, cmd[i])) {
- s = state[s][i];
- control = 1;
- break;
- }
- }
- if (!strcmp(a, "BB"))
- break;
- if (!strcmp(a, "RE"))
- s=0;
- if (control == 0 && strcmp(a,"RE"))
- printf("falsche Eingabe!!\n");
- }
- */
- //NR3
- printf("Ausgaben oder Eingabe\n");
- char a[100];
- scanf(" %s", a);
- char *token[10];
- strtok("HELLO WORLD", " ");
- stringParsen("HALLO WELT", &token[10]);
- system("pause");
- return 0;
- }
- void stringParsen(char *a, char**ptr[10]) {
- char *token = (char *)malloc(sizeof(char*));
- token = strtok(a, " ");
- *ptr[0] = token;
- while (token) {
- token = strtok(NULL," ");
- *ptr[0] = token;
- }
- }
- void init(node_t* root) {
- root->left = NULL;
- root->right = NULL;
- root->daten = 42;
- }
- //LR 0 für links 1 für rechts
- void append(node_t* root, unsigned int LR, dataT data) {
- if (LR > 1)
- return EXIT_FAILURE;
- //links anhängen
- if (LR == 0) {
- root->left = (node_t *)malloc(sizeof(node_t));
- root->left->left = NULL;
- root->left->right = NULL;
- root->left->daten = data;
- }
- //rechts anhängen
- else {
- root->right = (node_t *)malloc(sizeof(node_t));
- root->right->right = NULL;
- root->right->left = NULL;
- root->right->daten = data;
- }
- }
- void balance(node_t* root) {
- //abruchbedingung
- printf("%p\n", root);
- if (root == NULL || (root->left == NULL && root->right == NULL))
- return;
- //baum rekursiv durchegehen (preorder)
- if (root->left != NULL && root->daten < root->left->daten) {
- dataT buffer = root->left->daten;
- root->left->daten = root->daten;
- root->daten = buffer;
- }
- if (root->right != NULL && root->daten > root->right->daten) {
- dataT buffer = root->right->daten;
- root->right->daten = root->daten;
- root->daten = buffer;
- }
- balance(root->left);
- balance(root->right);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement