Savol 2 ta halqasimon ro’yhatni galma-galdan har 3-elementidan umumiy bitta yangi ro’yhat hosil qiling. Dastur kodi
Download 389.9 Kb.
|
Xayotov
- Bu sahifa navigatsiya:
- DASTUR NATIJASI
Muhammad al-xorazmiy nomidagi TATUning Telekomunikatsiya texnologiyalari Fakulteti 410-21-guruh talabasi Xayotov Xasanning malumotlar tuzilmasi va Algoritmlar SWD015-1 bajargan ishi Tekshirdi:Isxakova Nargiza Patxillaevna SAVOL 2 ta halqasimon ro’yhatni galma-galdan har 3-elementidan umumiy bitta yangi ro’yhat hosil qiling. DASTUR KODI #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 printList(Node *head) { Node *temp = head; while (temp != NULL) { cout< temp = temp->next; } cout< void merge(Node *p, Node **q) { Node *p_curr = p, *q_curr = *q; Node *p_next, *q_next; while (p_curr != NULL && q_curr != NULL) { p_next = p_curr->next; q_next = q_curr->next; q_curr->next = p_next; p_curr->next = q_curr; p_curr = p_next; q_curr = q_next; } *q = q_curr; } int main() { Node *p = NULL, *q = NULL; push(&p, 3); push(&p, 2); push(&p, 1); cout<<"Birinchi bog'langan ro'yxat:\n"; printList(p); push(&q, 8); push(&q, 7); push(&q, 6); push(&q, 5); push(&q, 4); cout<<"Ikkinchi bog'langan ro'yxat:\n"; printList(q); merge(p, &q); cout<<"O'zgartirilgan birinchi bog'langan ro'yxat:\n";
cout<<"O'zgartirilgan ikkinchi bog'langan ro'yxat:\n"; printList(q); return 0; } DASTUR NATIJASI Download 389.9 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling