Qobiljonov Anvarjon Navbat bog’langan ro’yxatlar asosida enqueue funksiyasidan foydalanib 5,17,3,5,15,18 qiymatlar kiritilsin. Eng birinchi qiymat ekranga chiqarilsin, dequeue funksiyasidan foydalanib ta qiymat o’chirilsin
Download 233.21 Kb.
|
Tatu ff tt va kt telekomunikatsiya yo\'nalishi 632-20 guruh talab
640-21 Qobiljonov Anvarjon Navbat bog’langan ro’yxatlar asosida enqueue() funksiyasidan foydalanib 15,17,3,5,15,18 qiymatlar kiritilsin. Eng birinchi qiymat ekranga chiqarilsin, dequeue() funksiyasidan foydalanib 2 ta qiymat o’chirilsin. O’zgartirilgandagi qolgan qiymatlar peek() va display() dan foydalangan xolda qayta ekranga chiqarilsin? 1. #include #include #define SIZE 5 using namespace std; class Queue{ private: int items[SIZE], front, rear; public: Queue(){ front=-1; rear=-1; } bool isFull(){ if(front==0&& rear==SIZE -1){ return true; } return false; } bool isEmpty(){ if (front==-1) return true; else return false; } void enQueue (int element){ if (isFull()){ cout << "Queue to'lgan"; } else { if (front == -1) front=0; rear++; items[rear]=element; cout< } int dequeue(){ int element; if (isEmpty()){ cout <<"Queue to'lgan"< } else{ element=items[front]; if (front>=rear){ front =-1; rear=-1; } else{ front++; } cout << endl<<"olib tashlash"< } } void display() { int i; if (isEmpty()){ cout << endl<< "Queue Bosh"<< endl; } else{ cout << endl << "front" << front; cout << endl << "elementlar"; for (i=front; i<=rear; i++) cout << items[i]<< "\t"; cout << endl << "front"<< front; for (i=front; i<=rear; i++) cout << endl<< "front"< for (i=front; i<=rear; i++) cout < } }; int main() { Queue q; q.enQueue(15); q.enQueue(17); q.enQueue(3); q.enQueue(5); q.enQueue(15); q.enQueue(18); q.display(); q.dequeue(); q.display(); return 0; } 2.
#include #include using namespace std; void showdg(deque { deque for (it = g.begin(); it !=g.end(); ++it) cout << '\t' << *it; cout << '\n'; } int main() { deque gquiz.push_back(5); gquiz.push_front(25); gquiz.push_back(18); gquiz.push_front(33); cout << "bu dek : "; showdg(gquiz); cout << "\ngquiz.size() : " << gquiz.size(); cout << "\ngquiz.max_size : " << gquiz.max_size(); cout << "\ngquiz.at(2) : " << gquiz.at(2); cout << "\ngquiz.front() : " << gquiz.front(); cout << "\ngquiz.back() : " << gquiz.back(); cout << "\ngquiz.pop_front() : " ; gquiz.pop_front(); showdg(gquiz); cout << "\ngquiz.pop_back() : "; gquiz.pop_back(); showdg(gquiz); return 0; } 3. Binary tree strukturasidan foydalanib ushbu chizmani dasturiy kodini tartibi bo’yicha tuzing va ekranga chiqaring. #include #include using namespace std; class node{ public: int info; node *left; node *right; }; int intrave(node *tree){ if (tree!=NULL){int a=0, b=0 if (tree->left!=NULL){a=tree->left->info}; if (tree->right!=NULL){a=tree->right->info;} cout << tree->info<<"--chapida=>"<intrave(tree->left); intrave(tree->right);} return 0; } node *del(node *tree,int key){ node *p=new node; node *next=tree; node *q=NULL; while (next!=NULL) {if (next->info==key){cout<<"binar daraxtda" << "key" << "mavjud" << endl; p=next; break; } if (next->info>key){q=next;next=next->left; } } if(next==NULL) cout <<"tuzilmada izlangan element yo'q"< if(p->left==NULL) v=p->right; else if(p->right==NULL) v=p->left; if((p->left!=NULL)&&(p->right!=NULL)){t=p; v=p->right; s=v->left} while(s!=NULL){ t=v; v=s; s=v->left; } if((t!=NULL)&&(t!=p)){ t->left=v->right; v->right=p->right; v->left=p->left; } if(t==p) v->left=p->left; if(q==NULL){ cout < tree=v; delete(p); return tree; } } int main() { int n,key,s; node *tree=NULL, *next=NULL; cout << "n="; cin>> n; for(int i=0; i node *last=new node; cin>>s; p->info=s; p->left=NULL; p->right=NULL; if(i==0){tree=p; next=tree; continue;} next=tree; while(1) {last=next; if(p->info else next=next->right; if(next==NULL)break; } if(p->info else last->right=p; } cout << endl; intrave (tree); cout << "delete qilinadigan elementni kiriting \n"; cout << "key="; cin >> key; tree=del(tree, key); intrave(tree); getch(); return 0; } 4. Arrayni binary daraxtga implementatsiya qilgan xolda yuqoridagi chizmani dasturiy kodini tartibi bo’yicha tuzing va ekranga chiqaring. #include #include using namespace std; class node{ public: int info; node Kleft; node ?right; }; int k=6; int intrave(node *tree){ if (tree!=NULL){int a=1, b=2; if (tree->1eft!=NULL){ a=tree->1eft->info; } if (tree->right!=NULL){ b=tree->right->info; } cout< intrave(tree—>right); } return 0; } int height(node *tree){ int h1,h2; if (tree==NULL) return (-1); else { h1 = height(tree—>1eft); h2 = height(tree—>right); if (h1>h2) return (1 + h1); else return (1 + hZ); } } int create_arr(node *tree,int xarr){ if(ltree) return 6; else{ create_arr(tree->1eft,arr); arr[k++]=tree->info; create_arr(tree—>right,arr); } } node *new_tree(int $arr, int start, int end) { else 1ast->right=p;} cout< cout<<"\nya'ni\n"; vizua1(tree,6); int h=height(tree); cout<<"balandligi="< for(int i=6;i vizua1(tree,e); getch(); } 5. Binar daraxt tuzilmasidan foydalanib yuqoridagi chizmani dasturiy kodi tuzilsin va ekranga inorder, preorder, postorder tartibida chiqarilsin. #include #include using namespace std; class node{ public: int info; node Ileft; node 3right; }; int k=0,F1ag=1; int height(node *tree){ int h1,h2; if (tree==NULL) return (—1); else { h1 = height(tree->1eft); h2 = height(tree->right); if (h1>h2) return (1 + hl); else return (1 + h2); } } void vizua1(node $tree,int l) { int i; if(tree1=NULL) { vizua1(tree—>right,l+1); for (i=1; i<=1; i++) cout<<" "; cout< } } int AVLtree (node *tree){ int t; if (tree!=NULL){ t = height (tree->1eft) - height (tree->right); if ((t<-1) ]| (t>1)) { Flag = 6; return Flag; } AVLtree (tree—>1eft); AVLtree (tree—>right); } } int GetFlag(){return Flag;} int main() { int n,key,s; node *tree=NULL,3next:NULL; cout<<"n="; cin>>n; int arr[n]; for(int i=9; i node Klast=new node; cin>>s; p->info=s; p->1eft=NULL; p->right=NULL; if(i==@){tree=p; next=tree; continue; } next=tree3 while(1) { last=next3 if(p->info else next=next~>right3 if(next==NULL)break; } if(p->info else 1ast—>right=p;} cout< vizual(tree,@); AVLtree(tree); if(GetFlag()) cout<<"ha, muvozanatlangan daraxt"; else cout<<"yo’q, muvozanatlanmagan daraxt"; cout< } 6. . Graflarning ro’yxat tuzilmasidan foydalanib yuqoridagi chizmani dasturiy kodi tuzilsin va ekranga chiqarilsin. #include #include #define SIZE 6 int main() { int a[SIZE][SIZE]; int d[SIZE]; int v[SIZE]; int temp, minindex, min; int begin_index = 9; ("chcp 1251"); (”cls"); for (int i = 6; i a[i][i] = 6; * for (int j = i + 1; j ("%d", atemp); ali][j] = temp; aHi] = team } } for (int i = 6; i Download 233.21 Kb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling