Skip to content
Snippets Groups Projects
Commit 3fb64bf2 authored by Peter Gerwinski's avatar Peter Gerwinski
Browse files

Beispielprogramme und Tafelbild 23.1.2017

parent b1a5b96b
Branches
No related tags found
No related merge requests found
20170123/photo-20170123-125804.jpg

149 KiB

#include <stdio.h>
typedef struct
{
int content;
node *left, *right;
} node;
int main (void)
{
node *root = NULL;
return 0;
}
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int content;
struct node *left, *right;
} node;
void insert (node **root, int content)
{
if (*root == NULL)
{
node *p = malloc (sizeof (node));
p->content = content;
p->left = NULL;
p->right = NULL;
*root = p;
}
else if (content > (*root)->content)
insert (&(*root)->right, content);
else
insert (&(*root)->left, content);
}
void output (node *root)
{
if (root)
{
output (root->left);
printf ("%d\n", root->content);
output (root->right);
}
}
int main (void)
{
node *root = NULL;
for (int i = 0; i < 30; i++)
insert (&root, rand () % 1000 + 1);
output (root);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int content;
struct node *left, *right;
} node;
void insert (node **root, int content)
{
if (*root == NULL)
{
node *p = malloc (sizeof (node));
p->content = content;
p->left = NULL;
p->right = NULL;
*root = p;
}
else if (content > (*root)->content)
insert (&(*root)->right, content);
else
insert (&(*root)->left, content);
}
void output (node *root)
{
if (root)
{
output (root->left);
printf ("%d\n", root->content);
output (root->right);
}
}
int output_tree_layer (node *root, int depth, int current_depth)
{
int result = 0;
if (root)
{
if (output_tree_layer (root->left, depth, current_depth + 1))
result = 1;
if (depth == current_depth)
{
printf ("%d ", root->content);
result = 1;
}
if (output_tree_layer (root->right, depth, current_depth + 1))
result = 1;
}
return result;
}
void output_tree (node *root)
{
if (root)
{
int depth = 0;
while (output_tree_layer (root, depth, 0))
{
printf ("\n");
depth++;
}
}
}
int main (void)
{
node *root = NULL;
for (int i = 0; i < 30; i++)
insert (&root, rand () % 1000 + 1);
output_tree (root);
return 0;
}
#include <stdio.h>
typedef struct node
{
int content;
struct node *left, *right;
} node;
int main (void)
{
node *root = NULL;
return 0;
}
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int content;
struct node *left, *right;
} node;
void insert (node *root, int content)
{
node *p = malloc (sizeof (node));
p->content = content;
p->left = NULL;
p->right = NULL;
root = p;
}
void output (node *root)
{
if (root)
printf ("%d\n", root->content);
}
int main (void)
{
node *root = NULL;
insert (root, 7);
output (root);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int content;
struct node *left, *right;
} node;
void insert (node **root, int content)
{
node *p = malloc (sizeof (node));
p->content = content;
p->left = NULL;
p->right = NULL;
*root = p;
}
void output (node *root)
{
if (root)
printf ("%d\n", root->content);
}
int main (void)
{
node *root = NULL;
insert (&root, 7);
output (root);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int content;
struct node *left, *right;
} node;
void insert (node **root, int content)
{
node *p = malloc (sizeof (node));
p->content = content;
p->left = NULL;
p->right = NULL;
*root = p;
}
void output (node *root)
{
if (root)
printf ("%d\n", root->content);
}
int main (void)
{
node *root = NULL;
insert (&root, 7);
insert (&root, 137);
insert (&root, 3);
insert (&root, 5);
output (root);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int content;
struct node *left, *right;
} node;
void insert (node **root, int content)
{
node *p = malloc (sizeof (node));
p->content = content;
p->left = NULL;
p->right = NULL;
if (*root == NULL)
*root = p;
else if (content > (*root)->content)
{
if ((*root)->right == NULL)
(*root)->right = p;
else
/* ??? */;
}
else
{
if ((*root)->left == NULL)
(*root)->left = p;
else
/* ??? */;
}
}
void output (node *root)
{
if (root)
printf ("%d\n", root->content);
}
int main (void)
{
node *root = NULL;
insert (&root, 7);
insert (&root, 137);
insert (&root, 3);
insert (&root, 5);
output (root);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int content;
struct node *left, *right;
} node;
void insert (node **root, int content)
{
node *p = malloc (sizeof (node));
p->content = content;
p->left = NULL;
p->right = NULL;
if (*root == NULL)
*root = p;
else if (content > (*root)->content)
{
if ((*root)->right == NULL)
(*root)->right = p;
else
/* ??? */;
}
else
{
if ((*root)->left == NULL)
(*root)->left = p;
else
/* ??? */;
}
}
void output (node *root)
{
if (root)
{
output (root->left);
printf ("%d\n", root->content);
output (root->right);
}
}
int main (void)
{
node *root = NULL;
insert (&root, 7);
insert (&root, 137);
insert (&root, 3);
insert (&root, 5);
output (root);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int content;
struct node *left, *right;
} node;
void insert (node **root, int content)
{
if (*root == NULL)
{
node *p = malloc (sizeof (node));
p->content = content;
p->left = NULL;
p->right = NULL;
*root = p;
}
else if (content > (*root)->content)
insert ((*root)->right, content);
else
insert ((*root)->left, content);
}
void output (node *root)
{
if (root)
{
output (root->left);
printf ("%d\n", root->content);
output (root->right);
}
}
int main (void)
{
node *root = NULL;
insert (&root, 7);
insert (&root, 137);
insert (&root, 3);
insert (&root, 5);
output (root);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int content;
struct node *left, *right;
} node;
void insert (node **root, int content)
{
if (*root == NULL)
{
node *p = malloc (sizeof (node));
p->content = content;
p->left = NULL;
p->right = NULL;
*root = p;
}
else if (content > (*root)->content)
insert (&(*root)->right, content);
else
insert (&(*root)->left, content);
}
void output (node *root)
{
if (root)
{
output (root->left);
printf ("%d\n", root->content);
output (root->right);
}
}
int main (void)
{
node *root = NULL;
insert (&root, 7);
insert (&root, 137);
insert (&root, 3);
insert (&root, 5);
output (root);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment