Binary tree (ikili ağaç) C programlama Veri yapıları.
#include<stdlib.h>
#include<stdio.h>
struct node
{
int data;
struct node *left;
struct node *right;
};
struct node *newnode(int data)
{
struct node *new = malloc(sizeof(struct node));
new->data = data;
new->left = NULL;
new->right = NULL;
return new;
}
int main()
{
struct node *root = newnode(1);
root->left = newnode(2);
root->right = newnode(3);
root->left->left = newnode(4);
root->left->right = newnode(5);
root->right->left = newnode(6);
root->right->right = newnode(7);
printf("Binary tree ikili agac\n\n");
printf("Root : %d \n",root->data);
printf("root->left : %d \n",root->left->data);
printf("root->right : %d \n",root->right->data);
printf("root->left->left : %d \n",root->left->left->data);
printf("root->left->right : %d \n",root->left->right->data);
printf("root->right->left : %d \n",root->right->left->data);
printf("root->right->right : %d \n",root->right->right->data);
return 1;
}
Hiç yorum yok:
Yorum Gönder
Her yorum bilgidir. Araştırmaya devam...