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;
}
#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 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;
}
Forwarded from Python daturlash maktabi 🐍
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
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;
}
#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;
}
#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
1.Ketma-ket qidiruv usulidan foydalanib, ro‘yhatda berilgan kalitdan katta elementlarni toping
Forwarded from Deleted Account
MTA laboratoriya MI 2.docx
25.2 KB
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
@BekorchiStudentlar
@uz_python
Forwarded from Bคгคt๏ש (๏ŦŦเςเคl) ✔
MTA laboratoriya MI 3.docx
47.4 KB
Оёқ кийимингизнинг размери охирига 2 та (0) қўшинг, ундан туғилган йилингизни айириб юборинг . Унга ҳозирги йилни қўшинг. Охирги 2 та сон сизнинг ёшингиз!
@uz_python
•┈•┈•✿••❁📖❁••✿•┈•┈•
@uz_python
•┈•┈•✿••❁📖❁••✿•┈•┈•
Forwarded from Deleted Account
/*
RO’YHAT har ikkinchi elementi o’chirilsin.
*/
#include <bits/stdc++.h>
using namespace std;
int main() {
list <int> num_list;
int n,k;
cin>>n;
for(int i=0;i<n;i++)
{ cin>>k;num_list.push_back(k); }
size_t size = num_list.size();
cout<<"natija: ";
list <int> :: iterator it = num_list.begin();
while(size--)
{ auto toDelete = it; it++;
if (size%2==1) num_list.erase(toDelete); }
for(it = num_list.begin();
it != num_list.end(); ++it)
{ cout << *it << " "; }
cout << endl; return 0; }
RO’YHAT har ikkinchi elementi o’chirilsin.
*/
#include <bits/stdc++.h>
using namespace std;
int main() {
list <int> num_list;
int n,k;
cin>>n;
for(int i=0;i<n;i++)
{ cin>>k;num_list.push_back(k); }
size_t size = num_list.size();
cout<<"natija: ";
list <int> :: iterator it = num_list.begin();
while(size--)
{ auto toDelete = it; it++;
if (size%2==1) num_list.erase(toDelete); }
for(it = num_list.begin();
it != num_list.end(); ++it)
{ cout << *it << " "; }
cout << endl; return 0; }
Forwarded from Deleted Account
/*
Stek elementlari teskari tartibda joylashtirib chiqilsin.
*/
#include<bits/stdc++.h>
using namespace std;
stack<char> st;
string ns;
char pastki_qismiga_joylashtir(char x)
{
if(st.size() == 0)
st.push(x);
else
{
char a = st.top();
st.pop();
pastki_qismiga_joylashtir(x);
st.push(a);
}
}
char teskari()
{
if(st.size()>0)
{
char x = st.top();
st.pop();
teskari();
pastki_qismiga_joylashtir(x);
}
}
int main()
{ st.push('1');
st.push('2');
st.push('3');
st.push('4');
cout<<"Asosiy Stack"<<endl;
cout<<"1"<<" "<<"2"<<" "
<<"3"<<" "<<"4"
<<endl;
teskari();
cout<<"teskari Stack"
<<endl;
while(!st.empty())
{
char p=st.top();
st.pop();
ns+=p; }
cout<<ns[3]<<" "<<ns[2]<<" "
<<ns[1]<<" "<<ns[0]<<endl;
return 0;
}
Stek elementlari teskari tartibda joylashtirib chiqilsin.
*/
#include<bits/stdc++.h>
using namespace std;
stack<char> st;
string ns;
char pastki_qismiga_joylashtir(char x)
{
if(st.size() == 0)
st.push(x);
else
{
char a = st.top();
st.pop();
pastki_qismiga_joylashtir(x);
st.push(a);
}
}
char teskari()
{
if(st.size()>0)
{
char x = st.top();
st.pop();
teskari();
pastki_qismiga_joylashtir(x);
}
}
int main()
{ st.push('1');
st.push('2');
st.push('3');
st.push('4');
cout<<"Asosiy Stack"<<endl;
cout<<"1"<<" "<<"2"<<" "
<<"3"<<" "<<"4"
<<endl;
teskari();
cout<<"teskari Stack"
<<endl;
while(!st.empty())
{
char p=st.top();
st.pop();
ns+=p; }
cout<<ns[3]<<" "<<ns[2]<<" "
<<ns[1]<<" "<<ns[0]<<endl;
return 0;
}