Tekshurdi: zaripov fazilbek
Download 263.52 Kb.
|
- Bu sahifa navigatsiya:
- include include using namespace std; void showq(queue gq) { queue g = gq;
O‘ZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI VA KOMMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI 3-AMALIYOT ISHI FAN:MALUMOTLAR TUZULMASI VA ALGORITMLASH BAJARDI:KARIMXO’JAYEV RAMAZONXO’JA TEKSHURDI:ZARIPOV FAZILBEK GURUH:SWD019-2 1-VAZIFA 6. N o’lchamli sonli qiymatdagi to’plam berilgan. Dinamik massiv ko’rinishida navbat yaratilsin va to’plam elementlari navbatga qo’shilsin. Navbat boshidan 1 ta element olinsin va ekranga chiqarilsin. Navbatga yangi 1 ta element qo’shilsin. Navbat barcha elementlari ekranga chiqarilsin. #include #include using namespace std; void showq(queue { queue while (!g.empty()) { cout << ' ' << g.front(); g.pop(); } cout << '\n'; } int main() { queue int p; cout<<"Navbat elementlari sonini kiriting:\n"; cin>>p; cout<<"Navbat elementlarini kiriting:\n"; for(int i=1;i<=p;i++) { int a; cin>>a; gquiz.push(a); } cout<<"Navbat elementlari:\n"; showq(gquiz); gquiz.pop(); cout<<"\nBoshidan bitta element olib tashlandi:\n"; showq(gquiz); cout<<"\nYangi element qo'shing:\n"; int yangi; cin>>yangi; gquiz.push(yangi); cout<<"Navbat elementlari:\n"; showq(gquiz); return 0; } 2-VAZIFA
#include using namespace std; class Node{ public: int data; Node* next; }; void push(Node** head_ref, int new_data) { Node* new_node = new Node(); new_node->data = new_data; new_node->next = (*head_ref); (*head_ref) = new_node; } void deleteNode(Node** head_ref, int key) { Node* temp = *head_ref; Node* prev = NULL; if (temp != NULL && temp->data == key) { *head_ref = temp->next; delete temp; return; } else { while (temp != NULL && temp->data != key) { prev = temp; temp = temp->next; } if (temp == NULL) return; prev->next = temp->next; delete temp; } } void printList(Node* node) { while (node != NULL) { cout << node->data << " "; node = node->next; } } int main() { int p; cout<<"Ro'yxat elementlari sonini kiriting:\n"; cin>>p; cout<<"Ro'yxat elementlarini kiriting:\n"; Node* head = NULL; int d; for(int i=1;i<=p;i++) { int a; cin>>a; push(&head, a); if(i==p) d=a; } puts("Ro'yxat elementlari: "); printList(head); deleteNode(&head, d); puts("\nBoshidan bitta element olib tashlandi: "); printList(head); puts("\nYangi element qo'shing: "); int yangi; cin>>yangi; push(&head, yangi); puts("Ro'yxat elementlari: "); printList(head); return 0; } Download 263.52 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling