Python daturlash maktabi ๐Ÿ
580 subscribers
343 photos
180 videos
83 files
389 links
Download Telegram
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;
}
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;
}
#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<<" ";
}
}
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; }
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;
}
Forwarded from Deleted Account
#include <iostream>
#include<deque>
///Navbat juft elementlari o'chirilsin
using namespace std;

int main()
{
deque <int> navbat1,navbat;
int n;
cout<<"n= "; cin>>n;
cout<<"navbat elementlarini kiriting: ";
for(int i=0;i<n;i++)
{ int k;
cin>>k;
navbat.push_back(k);
}
int k=0;
for(int i:navbat)
{
if(k%2==0) navbat1.push_back(i);
k++;
navbat.pop_front();
}cout<<"\n navbat juft o'rnidagi elementlari o'chirilsin: ";
for(int j:navbat1)
{
cout<<j<<" ";
}

return 0;
}
image_2019-11-16_22-26-56.png
2.9 KB
#include <iostream>
#include<deque>
using namespace std;

int main()
{
deque <int> navbat1,navbat;
int n;
cout<<"n= "; cin>>n;
cout<<"navbat elementlarini kiriting: ";
for(int i=0;i<n;i++)
{ int k;
cin>>k;
navbat.push_back(k);
}
int k=0;
int min=navbat.front();
for(int i:navbat)
{ if(i<min)min=i;
}
for(int i:navbat)
{
if(i==min) navbat1.push_back(0);
else navbat1.push_back(i);
k++;
navbat.pop_front();
}

cout<<"\n navbatni minimal elementi o'rniga 0 joylashtirilsin: ";
for(int j:navbat1)
{
cout<<j<<" ";
}

return 0;
}
image_2019-11-16_23-31-14.png
3.2 KB
#include <iostream>
#include<deque>
using namespace std;

int main()
{
deque <int> navbat1,navbat;
int n;
cout<<"n= "; cin>>n;
cout<<"navbat elementlarini kiriting: ";
for(int i=0;i<n;i++)
{ int k;
cin>>k;
navbat.push_back(k);
}
int k=0;
int min=navbat.front();
for(int i:navbat)
{ if(i<min)min=i;
}
for(int i:navbat)
{ navbat1.push_back(i);
if(i==min) navbat1.push_back(0);

k++;
navbat.pop_front();
}

cout<<"\n navbatni minimal elementidan keyingi o'rniga 0 joylashtirilsin: ";
for(int j:navbat1)
{
cout<<j<<" ";
}

return 0;
}
Python daturlash maktabi ๐Ÿ
Photo
/*
Ikki ro'yhat birlashtirilsin

*/


#include <bits/stdc++.h>
using namespace std;
int main()
{
list<int> list1,list2;
int n,m;
cout<<"1- list elementlari soni: "; cin>>n;
cout<<"1- list elementlarini kiriting: ";
for(int i=0;i<n;i++)
{ int k;
cin>>k;
list1.push_back(k);
}
cout<<"2- list elementlari soni: "; cin>>m;
cout<<"2- list elementlarini kiriting: ";
for(int i=0;i<m;i++)
{ int k;
cin>>k;
list2.push_back(k);
}

list2.merge(list1);
cout << "List: ";
for (auto i = list2.begin(); i != list2.end(); ++i)
cout << *i << " ";
return 0;
}
Forwarded from Bเธ„ะณเธ„tเนืฉ (เนลฆลฆเน€ฯ‚เน€เธ„l) โœ”
#include<bits/stdc++.h>
using namespace std;
struct KOMPUTER
{
int id;
string nomi;
string YILI;
string XOTIRASI;
};

int main()
{ int n,k,d;
KOMPUTER a[10];
deque<int> myDeque;
a[0].id=1; a[0].nomi= "HP "; a[0].XOTIRASI="1024 GB"; a[0].YILI="2012";
a[1].id=2; a[1].nomi= "ACER "; a[1].XOTIRASI="1024 GB"; a[1].YILI="2015";
a[2].id=3; a[2].nomi= "SAMSUNG "; a[2].XOTIRASI="512 GB"; a[2].YILI="2018";
a[3].id=4; a[3].nomi= "LG "; a[3].XOTIRASI="2048 GB"; a[3].YILI="2019";
a[4].id=5; a[4].nomi= "TOSHIBA "; a[4].XOTIRASI="1024 GB"; a[4].YILI="2019";
a[5].id=6; a[5].nomi= "APPLE "; a[5].XOTIRASI="1024 GB"; a[5].YILI="2016";
a[6].id=7; a[6].nomi= "SAMSUNG "; a[6].XOTIRASI="512 GB"; a[6].YILI="2014";
a[7].id=8; a[7].nomi= "AVTECH "; a[7].XOTIRASI="1024 GB"; a[7].YILI="1996";
a[8].id=9; a[8].nomi= "LINUX "; a[8].XOTIRASI="1024 GB"; a[8].YILI="2000";
a[9].id=10; a[9].nomi="ASUS "; a[9].XOTIRASI="512 GB"; a[9].YILI="2017";
for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
if(i!=j && a[i].nomi==a[j].nomi) myDeque.push_back(i);
}
}



cout<<endl<<"Tr"<<"\t"<<"id:"<<"\t"<<"Nomi:""\t"<<" YILI:"<<"\t"<<" XOTIRASI:"<<endl;
for (int i=0;i<10; i++)
{
cout<<i+1<<"\t"<<a[i].id<<"\t"<<a[i].nomi<<"\t\t"<<a[i].YILI<<"\t\t"<<a[i].XOTIRASI<<endl;
}
cout<<"\n Navbat orqali bir xil nomli KOMPUTERLARni ekranga chiqarildi: ";
cout<<endl<<"Tr"<<"\t"<<"id:"<<"\t"<<"Nomi:""\t"<<" YILI:"<<"\t"<<" XOTIRASI:"<<endl;
for(int i = 0; i < myDeque.size(); i++) {
cout<<i+1<<"\t"<<a[ myDeque[i]].id<<"\t"<<a[ myDeque[i]].nomi<<"\t\t"<<a[ myDeque[i]].YILI<<"\t\t"<<a[ myDeque[i]].XOTIRASI<<endl;
}

return 0;
}
2 ta roโ€™yhatning bir xil qiymatli elementlaridan yangi halqasimon roโ€™yhat yarating

#include <iostream>
using namespace std;
class Node{
public: int number;
Node* next;
};
int main()
{ Node* head = NULL;
Node* lastPtr = NULL;
short action = -1;
while (1)
{ cout<<"1. 1- guruh raqam berish\n";
cout<<"2 2-guruh raqam berish:\n";
cout<<"3. ro'yhatni ko'rish\n";
cout<<"4 ro'yxatni korish\n";
cout<<" qushish\n";
cout<<"0. chiqish\n";
cout<<"tanlang: ";
cin>>action;
if (action == 0) {
system("CLS");
break;}
if (action == 1)
{ //system("CLS");
Node* ptr = new Node;
int numb = -1;

cout<<"son kiriting: ";
cin>>numb;
ptr->number = numb;
ptr->next = NULL;
if (head == 0)
{ head = ptr;
lastPtr = ptr;
// system("CLS");
continue;
}
lastPtr->next = ptr;
lastPtr = ptr;
//system("CLS");
continue;
}
if (action == 3){
Node* ptr = NULL;
//system("CLS");
if (head == 0)
{ cout<<"\t!!! ro'yhat bo'sh !!!\n\n";
system("PAUSE");
system("CLS");
continue;
}
cout<<"* * * * * ro'yhat * * * * *\n\n";
ptr = head;
while (1) {
cout<<ptr->number<<" ";
if (ptr->next == 0) break;

ptr = ptr->next;
}
cout<<"\n\n";
system("PAUSE");
//system("CLS");
continue;
}

if (action == 2)
{ //system("CLS");
Node* ken = new Node;
int numb = -1;

cout<<"son kiriting: ";
cin>>numb;
ken->number = numb;
ken->next = NULL;
if (head == 0)
{ head = ken;
lastPtr = ken;
// system("CLS");
continue;
}
lastPtr->next = ken;
lastPtr = ken;
system("CLS");
continue;
}
if (action == 4){
Node* ken = NULL;
//system("CLS");
if (head == 0)
{ cout<<"\t!!! ro'yhat bo'sh !!!\n\n";
system("PAUSE");
system("CLS");
continue;
}
cout<<"* * * * * ro'yhat * * * * *\n\n";
ken = head;
while (1) {
cout<<ken->number<<" ";
if (ken->next == 0) break;

ken = ken->next;
}
cout<<"\n\n";
system("PAUSE");
//system("CLS");
continue;
}
if(action==5)
{
Node* qush = NULL;
system("CLS");
Ro'yhat Kiritilgan sonlarningn har 3chisini o`chiruvchi dastur tuzing.

Dastur kodi:
#include <bits/stdc++.h>
using namespace std;
int main() {
list <int> num_list;
int n,k;
cout<<"Nechta son kiritasiz: ";
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%3==1) num_list.erase(toDelete); }
for(it = num_list.begin();
it != num_list.end(); ++it)
{ cout << *it << " "; }
cout << endl; return 0; }
Dastur natijasi:

Nechta son kiritasiz: 10
1 2 3 4 5 6 7 8 9 10
natija: 1 2 4 5 7 8 10
/* 2ta nxn matitsani ko'paytirish */
#include<iostream>
#include<vector>
using namespace std;
int a[10][10],b[10][10],H[10][10];
int main(){

int n; cout<<"n: "; cin>>n;
cout<<"a["<<n<<"]["<<n<<"] : \n";
for (int i = 0; i < n; i++){
for (int j = 0; j< n; j++){
cin>>a[i][j];
}}
cout<<"b["<<n<<"]["<<n<<"] : \n";
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
cin>>b[i][j];
}}



for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
// H[i][j] = 0;
for (int t = 0; t < n; t++){
H[i][j] += a[i][t] * b[t][j];

}
}
}
cout<<"a["<<n<<"]["<<n<<"]xb["<<n<<"]["<<n<<"] :\n";
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
cout<< H[i][j]<<" " ;
}cout<<endl;
}



}
/*
15-masala. Lotoreya ishtirokchilari familiyalari va mukofotlar nomlaridan tashkil topgan 2 ta halqasimon roโ€™yhat berilgan. N ta ishtirokchi gโ€™olib boโ€™lsin (har K-inchi). Mukofotlarni qayta hisoblash soni - t.
*/
#include <bits/stdc++.h>
using namespace std;
struct Node
{
int number;
string ismi;
Node* next;
};
int n;
struct Node* head = NULL;
struct Node* lastPtr = NULL;
void qushish()
{
Node* ptr = new Node;
int numb = -1; string a;
cout<<"o'yinchi raqamini kiriting: ";
cin>>numb;
cout<<" ismini kiriting: ";
cin>>a;
ptr->number = numb;
ptr->ismi = a;
ptr->next = NULL;
if (head == 0)
{
head = ptr;
lastPtr = ptr;
}
lastPtr->next = ptr;
lastPtr = ptr;
}
void chop_etish()
{
Node* ptr = NULL;
if (head == 0)
{
cout<<"\t!!! roโ€™yhat boโ€™sh !!!\n\n";
}
cout<<"* * * * * roโ€™yhat * * * * *\n\n";

ptr = head;
while (1)
{
cout<<ptr->number<<" ";
cout<<ptr->ismi<<" \n";
if (ptr->next == 0) break;
ptr = ptr->next;}
cout<<"\n\n";}
void golib(){
Node* p1 = head;
Node* q1 = new Node;
int k=rand()%(n-1)+1;
for (int i=0;i<k-1;i++) p1=p1->next;
q1 = p1->next;
p1->next = q1->next;
cout<<" go'lib o'yinchi!:\n";
cout<<q1->number<<" ";
cout<<q1->ismi;"\n\n";
}
int main()
{
cout<<" Ro'yhat elementlari sonini kiriting:\n";
cin>>n;
cout<<" Ro'yhat elementlarini kiriting:\n";
for(int i=0;i<n;i++)
{
qushish();
}
chop_etish();
golib();
}
/*
Mahsulot nomlaridan tashkil topgan roโ€™yhat berilgan. Roโ€™yhat elementlaridagi SONY firmasida ishlab chiqilgan mahsulotlardan tashkil topgan yangi roโ€™yhat yarating.

Algoritmi:
ContainsWord nomli mantiqiy funksiya yaratish;
Undan faqat true yoki false qiymat qaytaradi.
Royhat yaratish;
Ro
yhatga malumot kiritish;
Sony so
zini malumotda qatnashganligini tekshirish;
Sony so
zi qatnashgan malumotlarni chiqarish.
*/
Dasturiy ko
rinishi:
#include "iostream"
#include "string"
#include "list"
using namespace std;
bool containsWord(string word, string inLine) {
int wlen, counter = 0, slength = inLine.length() - word.length() + 1;
wlen = word.length();

for(int i = 0; i < slength; i++) {
for(int j = 0; j < word.length(); j++){
if(word[j] == inLine[i + j])
counter++;
else{
counter = 0;
break;
}
}

if(counter == wlen) {
return true;
}
counter = 0;
}
return false;
}
main()
{
list<string> brands;
brands.push_front("Televizor-Artel");
brands.push_front("Changyutgich-Roison");
brands.push_front("Telefon-Sony");
brands.push_front("Notebook-Asus");
brands.push_front("Konditsioner-Sony");
brands.push_front("Playstation-Sony");
brands.push_front("Muzlatgich-Artel");
brands.push_front("Blender-Artel");
brands.push_front("Televizor-Sony");
brands.push_front("Notebook-Acer");

string current, brand = "Sony";
list<string> sonyBrands, bCopy = brands;

for(int i = 0; i < brands.size(); i++) {
current = bCopy.front();
if(containsWord(brand, current)) {
sonyBrands.push_front(bCopy.front());
}
bCopy.pop_front();
}

list<string> copy = sonyBrands;
cout << endl << "Sony brendi ostidagi tovarlar:" << endl << endl;
for(int i = 0; i < sonyBrands.size(); i++) {
cout << copy.front() << endl;
copy.pop_front();
}
/*

4-Variant.

Royhat yarating, Royhatga N ta haqiqiy son kiriting. Royhatning minimum elementini ochirich dasturini tuzing.

Dastur Kodi:

*/
#include <iostream>
using namespace std;

class Node{

public:

int number;

Node* next;

};

int main()
{ int n;
cout<<"Ro'yhat Elementlari sonini kiriting: \n\n";
cin>>n;
Node* head = NULL;
Node* lastPtr = NULL;
cout<<"\nRo'yhat Elementlarini kiriting: \n\n";
for(int i=0;i<n;i++){

{
Node* ptr = new Node;
int numb = -1;
cin>>numb;
ptr->number = numb;
ptr->next = NULL;
if (head == 0)
{ head = ptr;
lastPtr = ptr;

continue;
}
lastPtr->next = ptr;
lastPtr = ptr;

continue; } }
{
Node* ptr = NULL;

if (head == 0)
{
cout<<"\t!!! Ro'yhat bosh !!!\n\n";
system("PAUSE");

}
cout<<"\nRo'yhat minimal elementlari o'chirildi!: \n\n";
ptr = head;
int min=ptr->number;
Node* q = new Node;
while(ptr){
if(min>ptr->number){ min=ptr->number;}
ptr=ptr->next; }
ptr = head;
while (1) {
if(min==ptr->number) {
delete(ptr);}
else cout<<ptr->number<<" ";
if (ptr->next == 0) break;
ptr = ptr->next; }

cout<<"\n\n";
system("PAUSE"); } }
#include <iostream>
#include <cstdlib>
using namespace std;

class BinarySearchTree
{
private:
struct tree_node
{
tree_node* left;
tree_node* right;
int data;
};
tree_node* root;
public:
BinarySearchTree()
{
root = NULL;
}
bool isEmpty() const { return root==NULL; }
void print_inorder();
void inorder(tree_node*);
void print_preorder();
void preorder(tree_node*);
void print_postorder();
void postorder(tree_node*);
void insert(int);
void remove(int);
};

// kichkina elementi chap tarafga joylashtiriladi

// kattaroq elementi o'ng tarafga joylashtiriladi
void BinarySearchTree::insert(int d)
{
tree_node* t = new tree_node;
tree_node* parent;
t->data = d;
t->left = NULL;
t->right = NULL;
parent = NULL;
// bu yangi daraxtmi?
if(isEmpty()) root = t;
else
{
// Izoh: HAMMA qo'shimchalar barg tugunlari kabi
tree_node* curr;
curr = root;
// Find the Node's parent
while(curr)
{
parent = curr;
if(t->data > curr->data) curr = curr->right;
else curr = curr->left;
}

if(t->data < parent->data)
parent->left = t;
else
parent->right = t;
}
}

void BinarySearchTree::remove(int d)
{
// Elementni toping
bool found = false;
if(isEmpty())
{
cout<<" This Tree is empty! "<<endl;
return;
}
tree_node* curr;
tree_node* parent;
curr = root;
while(curr != NULL)
{
if(curr->data == d)
{
found = true;
break;
}
else
{
parent = curr;
if(d>curr->data) curr = curr->right;
else curr = curr->left;
}
}
if(!found)
{
cout<<" Bunday son mavjud emas! "<<endl;
return;
}


/*// 3 ta holat:
// 1. Biz barg tugunini olib tashlaymiz
// 2. Biz bitta bola bilan tugunni olib tashlaymiz
// 3. biz 2 bolali tugunni olib tashlaymiz

// Bitta bolali tugun*/
if((curr->left == NULL && curr->right != NULL)|| (curr->left != NULL
&& curr->right == NULL))
{
if(curr->left == NULL && curr->right != NULL)
{
if(parent->left == curr)
{
parent->left = curr->right;
delete curr;
}
else
{
parent->right = curr->right;
delete curr;
}
}
else // chap bola hozir, o'ng bola yo'q
{
if(parent->left == curr)
{
parent->left = curr->left;
delete curr;
}
else
{
parent->right = curr->left;
delete curr;
}
}
return;
}

//We're looking at a leaf node
if( curr->left == NULL && curr->right == NULL)
{
if(parent->left == curr) parent->left = NULL;
else parent->right = NULL;
delete curr;
return;
}



/* 2 farzandli tugun
// tugmani o'ng pastki satrda eng kichik qiymat bilan almashtirish */
if (curr->left != NULL && curr->right != NULL)
{
tree_node* chkr;
chkr = curr->right;
if((chkr->left == NULL) && (chkr->right == NULL))
{
curr = chkr;
delete chkr;
curr->right = NULL;
}
else // o'ng farzandning bolalari bor
{
/* agar tugunning o'ng bolasida chap bolasi bo'lsa
// Kichkina elementni topish uchun chap tomonga pastga siljiting*/
๐Ÿ‘1