Python daturlash maktabi 🐍
573 subscribers
343 photos
180 videos
83 files
389 links
Download Telegram
Channel name was changed to Β«Uz_Python/C++/Java/C#Β»
#include <iostream>
#include<algorithm>
using namespace std;

int main()
{
int count, i, first, last, middle;
char arr[10],key;

cout<<"qancha element kiritmoqchisiz?:";
cin>>count;

for (i=0; i<count; i++)
{
cout<< " belgilarni kiriting "<<(i+1)<<": ";
cin>>arr[i];
}
cout<<endl<<endl;
sort(arr,arr+count);
for (i=0; i<count; i++)
{
cout<< " belgilarni kiriting "<<(i+1)<<": "<<arr[i]<<endl;
}

o:
cout<<"Kiritilgan belgilardan qayssi birini topmoqchisiz:";
cin>>key;
first = 0;
last = count-1;
middle = (first+last)/2;
while (first <= last)
{
if(arr[middle] < key)
{
first = middle + 1;

}
else if(arr[middle] == key)
{
cout<<key<<" kiritilgan belgilar ichida bor joylashuvi= "<<middle+1<< " - qatorda " <<"\n";
break;
}
else {
last = middle - 1;
}
middle = (first + last)/2;
}
if(first > last)
{
cout<<key<<" belgi topilmadi\n";
}
int a;
cout<<"Yana qidirib ko'rasizmi xa:1 yoq:0 ";cin>>a;
if(a==1) goto o;
else cout<<"Raxmat";
}
#Savol7 Binar daraxti berilgan bo'lsin. va undagi elementlar kalit qiymatiga teng elementlarni o'chirish dasturi tuzilsin
Python daturlash maktabi 🐍
#Savol7 Binar daraxti berilgan bo'lsin. va undagi elementlar kalit qiymatiga teng elementlarni o'chirish dasturi tuzilsin
#include<stdio.h>
#include<stdlib.h>



struct node
{

int key;

struct node *left, *right;
};



struct node *newNode(int 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("%d ", root->key);

inorder(root->right);

}
}


struct node* insert(struct node* node, int 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, int 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()
{

/*
50

/ \

30 70

/ \ / \

20 40 60 80 */

struct node *root = NULL;

root = insert(root, 50);

root = insert(root, 30);

root = insert(root, 20);

root = insert(root, 40);

root = insert(root, 70);

root = insert(root, 60);

root = insert(root, 80);



printf("Inorder traversal of the given tree \n");

inorder(root);



printf("\nDelete 20\n");

root = deleteNode(root, 20);

printf("Inorder traversal of the modified tree \n");

inorder(root);



printf("\nDelete 30\n");

root = deleteNode(root, 30);

printf("Inorder traversal of the modified tree \n");

inorder(root);



printf("\nDelete 50\n");

root = deleteNode(root, 50);

printf("Inorder traversal of the modified tree \n");

inorder(root);



return 0;
}
#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 orta 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;
}
This media is not supported in your browser
VIEW IN TELEGRAM
Barcha IT soxasida talim olayotganlar yani TATU da o'qiyotgan ko'pchilik 50-60% Talabalarga uy vazifa (deadline) va mustaqil ishlar ko'payib unga vaqti yetmayapti yoki uni Bajara olmayotkanlar uchun xam biz ularga yordam qilamiz. ( Kelishuv asosida muddat va misolni qiyinlik darajasi bo'yicha ishlab beradigon, bizda tajribali dasturchilar mavjud )
Murojat uchun :
Admin: @Frozen_ice
Channel: @uz_python
Python daturlash maktabi 🐍
Photo
2)

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
struct node
{
int key;
struct node *left, *right;
};
struct node *newNode(int item)
{
struct node *temp = (struct node *)malloc(sizeof(struct node));
temp->key = item;
temp->left = temp->right = NULL;
return temp;
}
int height(node *tree, int d){
if (tree->key == d) return 0;
else {
if (d > tree->key) return height(tree->right,d)+1;
else return height(tree->left,d)+1;
}
}
int intrave(node *tree){
if(tree!=NULL) {
intrave(tree->left);
cout<<tree->key<<" ";
intrave(tree->right);
}
return 0;
}


struct node* insert(struct node* node, int 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;
}


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);
}
int a;
cout<<"Kerakli tugun kalit qiymatini kiriting: "; cin>>a;

intrave(root);
cout<<endl;
cout<<"Berilgan tugungacha masofa: "<<height(root,a);

return 0;
}
Python daturlash maktabi 🐍
Photo
2)


#include<iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
struct node
{
int key;
struct node *left, *right;
};
int arr[12];
int i=0,k=0;
struct node *T = NULL;
struct node *newNode(int item)
{
struct node *temp = (struct node *)malloc(sizeof(struct node));
temp->key = item;
temp->left = temp->right = NULL;
return temp;
}

int pretrave(node *tree){
if(tree!=NULL) {int a=0,b=0;
if(tree->left!=NULL) a=tree->left->key;
if(tree->right!=NULL) b=tree->right->key;
cout<<tree->key<<" - chapida "<<a<<" - o`ngida "<<b<<" \n";
pretrave(tree->left);
pretrave(tree->right);
}
return 0;
}

int intrave(node *tree){
if(tree!=NULL) {
intrave(tree->left);
arr[i++]=tree->key;
intrave(tree->right);
}
return 0;
}

node *new_tree(int *arr, int start, int end){
if(start>end) return NULL;
else {
int mid=(start+end)/2;
node *tree=new node;
tree->key=arr[mid];
tree->left=new_tree(arr,start,mid-1);
tree->right=new_tree(arr,mid+1,end);
return tree;
}
}

struct node* insert(struct node* node, int 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;
}
void insert_terminal(struct node *root)
{
if (root != NULL)
{
insert_terminal(root->left);
if(root->left == NULL && root->right == NULL){
T = insert(T,root->key);
k++;
}
insert_terminal(root->right);
}
}


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);
}

pretrave(root);
cout<<endl;
cout<<endl;


insert_terminal(root);
intrave(T);
T = new_tree(arr,0,k-1);

pretrave(T);
return 0;
}
#Savol1
1.Ketma-ket qidiruv usulidan foydalanib, roβ€˜yhatda berilgan kalitdan katta elementlarni toping
#include<iostream>
#include<list>
using namespace std;
int main(){

list <int> a;
for(int i=0;i<10;i++){

a.push_back(i+1);
}
int kalit;
cin>>kalit;

cout<<"Ro'yxat:\n";
for(int i:a){
cout<<i<<" ";}
cout<<endl;
for(int i:a){
if(i>kalit)
cout<<i<<" ";
}
}
This media is not supported in your browser
VIEW IN TELEGRAM
😁😁😁Dasturlashni endi boshlaganingda shunday bo'lishi mumkin lekin sen aslo chekinmaπŸ‘πŸ‘
@BekorchiStudentlar
@uz_python