#Javob10
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
struct node
{
float key;
struct node *left, *right;
};
struct node *newNode(float item)
{
struct node *temp = (struct node *)malloc(sizeof(struct node));
temp->key = item;
temp->left = temp->right = NULL;
return temp;
}
void inorder(struct node *root)
{
if (root != NULL)
{
inorder(root->left);
printf("%g ", root->key);
inorder(root->right);
}
}
struct node* insert(struct node* node, float key)
{
if (node == NULL) return newNode(key);
if (key < node->key)
node->left = insert(node->left, key);
else
node->right = insert(node->right, key);
return node;
}
struct node * minValueNode(struct node* node)
{
struct node* current = node;
while (current && current->left != NULL)
current = current->left;
return current;
}
struct node* deleteNode(struct node* root, float key)
{
if (root == NULL) return root;
if (key < root->key)
root->left = deleteNode(root->left, key);
else if (key > root->key)
root->right = deleteNode(root->right, key);
else
{
if (root->left == NULL)
{
struct node *temp = root->right;
free(root);
return temp;
}
else if (root->right == NULL)
{
struct node *temp = root->left;
free(root);
return temp;
}
struct node* temp = minValueNode(root->right);
root->key = temp->key;
root->right = deleteNode(root->right, temp->key);
}
return root;
}
int main()
{
struct node *root = NULL;
printf("Daraxt tugunlari soni: ");
int n;
cin>>n;
printf("Daraxt tugunlarini kiriting: \n");
float s=0;
for(int i=0; i<n; i++)
{
float temp;
cin>>temp;
s += temp;
root = insert(root, temp);
}
s /= n;
printf("\nDaraxtning tugunlari qiymatlarining o
inorder(root);
return 0;
}
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
struct node
{
float key;
struct node *left, *right;
};
struct node *newNode(float item)
{
struct node *temp = (struct node *)malloc(sizeof(struct node));
temp->key = item;
temp->left = temp->right = NULL;
return temp;
}
void inorder(struct node *root)
{
if (root != NULL)
{
inorder(root->left);
printf("%g ", root->key);
inorder(root->right);
}
}
struct node* insert(struct node* node, float key)
{
if (node == NULL) return newNode(key);
if (key < node->key)
node->left = insert(node->left, key);
else
node->right = insert(node->right, key);
return node;
}
struct node * minValueNode(struct node* node)
{
struct node* current = node;
while (current && current->left != NULL)
current = current->left;
return current;
}
struct node* deleteNode(struct node* root, float key)
{
if (root == NULL) return root;
if (key < root->key)
root->left = deleteNode(root->left, key);
else if (key > root->key)
root->right = deleteNode(root->right, key);
else
{
if (root->left == NULL)
{
struct node *temp = root->right;
free(root);
return temp;
}
else if (root->right == NULL)
{
struct node *temp = root->left;
free(root);
return temp;
}
struct node* temp = minValueNode(root->right);
root->key = temp->key;
root->right = deleteNode(root->right, temp->key);
}
return root;
}
int main()
{
struct node *root = NULL;
printf("Daraxt tugunlari soni: ");
int n;
cin>>n;
printf("Daraxt tugunlarini kiriting: \n");
float s=0;
for(int i=0; i<n; i++)
{
float temp;
cin>>temp;
s += temp;
root = insert(root, temp);
}
s /= n;
printf("\nDaraxtning tugunlari qiymatlarining o
rta arifmetigi: %g\n\n",s);
root = insert(root, s);
printf("Daraxtga %g qiymatli tugun qo
shildi ! \n\n",s); inorder(root);
return 0;
}
Python daturlash maktabi 🐍
#Savol10
#Javob10.2
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
struct node
{
float key;
struct node *left, *right;
};
struct node *newNode(float item)
{
struct node *temp = (struct node *)malloc(sizeof(struct node));
temp->key = item;
temp->left = temp->right = NULL;
return temp;
}
void inorder(struct node *root)
{
if (root != NULL)
{
inorder(root->left);
printf("%g ", root->key);
inorder(root->right);
}
}
void node_view(struct node *root)
{
if (root != NULL)
{
printf("%f ", root->key);
}
}
struct node* insert(struct node* node, float key)
{
if (node == NULL) return newNode(key);
if (key < node->key)
node->left = insert(node->left, key);
else
node->right = insert(node->right, key);
return node;
}
struct node * minValueNode(struct node* node)
{
struct node* current = node;
while (current && current->left != NULL)
current = current->left;
return current;
}
struct node* deleteNode(struct node* root, float key)
{
if (root == NULL) return root;
if (key < root->key)
root->left = deleteNode(root->left, key);
else if (key > root->key)
root->right = deleteNode(root->right, key);
else
{
if (root->left == NULL)
{
struct node *temp = root->right;
free(root);
return temp;
}
else if (root->right == NULL)
{
struct node *temp = root->left;
free(root);
return temp;
}
struct node* temp = minValueNode(root->right);
root->key = temp->key;
root->right = deleteNode(root->right, temp->key);
}
return root;
}
int main()
{
struct node *root = NULL;
printf("Daraxt tugunlari soni: ");
int n;
cin>>n;
printf("Daraxt tugunlarini kiriting: \n");
for(int i=0; i<n; i++)
{
float temp;
cin>>temp;
root = insert(root, temp);
}
inorder(root);
cout<<endl;
struct node *t_left = root->left;
struct node *t_right = root->right;
if((root->key)-(t_left->key) < (t_right->key)-(root->key)){
node_view(t_left);
}
else{
node_view(t_right);
}
return 0;
}
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
struct node
{
float key;
struct node *left, *right;
};
struct node *newNode(float item)
{
struct node *temp = (struct node *)malloc(sizeof(struct node));
temp->key = item;
temp->left = temp->right = NULL;
return temp;
}
void inorder(struct node *root)
{
if (root != NULL)
{
inorder(root->left);
printf("%g ", root->key);
inorder(root->right);
}
}
void node_view(struct node *root)
{
if (root != NULL)
{
printf("%f ", root->key);
}
}
struct node* insert(struct node* node, float key)
{
if (node == NULL) return newNode(key);
if (key < node->key)
node->left = insert(node->left, key);
else
node->right = insert(node->right, key);
return node;
}
struct node * minValueNode(struct node* node)
{
struct node* current = node;
while (current && current->left != NULL)
current = current->left;
return current;
}
struct node* deleteNode(struct node* root, float key)
{
if (root == NULL) return root;
if (key < root->key)
root->left = deleteNode(root->left, key);
else if (key > root->key)
root->right = deleteNode(root->right, key);
else
{
if (root->left == NULL)
{
struct node *temp = root->right;
free(root);
return temp;
}
else if (root->right == NULL)
{
struct node *temp = root->left;
free(root);
return temp;
}
struct node* temp = minValueNode(root->right);
root->key = temp->key;
root->right = deleteNode(root->right, temp->key);
}
return root;
}
int main()
{
struct node *root = NULL;
printf("Daraxt tugunlari soni: ");
int n;
cin>>n;
printf("Daraxt tugunlarini kiriting: \n");
for(int i=0; i<n; i++)
{
float temp;
cin>>temp;
root = insert(root, temp);
}
inorder(root);
cout<<endl;
struct node *t_left = root->left;
struct node *t_right = root->right;
if((root->key)-(t_left->key) < (t_right->key)-(root->key)){
node_view(t_left);
}
else{
node_view(t_right);
}
return 0;
}