Daraxtsimon tuzilmalarni tadqiq qilish individual topshiriqlar



Download 139,85 Kb.
Sana02.08.2021
Hajmi139,85 Kb.
#136485
Bog'liq
MTA laboratoriya-6


O'ZBЕKISTON RESPUBLIKASI AXBOROT

TEXNOLOGIYALARI VA KOMMUNIKATSIYALARINI

RIVOJLANTIRISH VAZIRLIGI
MUHAMMAD AL-XORAZMIY NOMIDAGI

TOSHKЕNT AXBOROT TЕXNOLOGIYALARI UNIVЕRSITЕTI

Labaratoriya Ishi-6
Guruh: 830-19

Bajardi: Gulimmatov Oxunjon


TOSHKENT 2020



6-LABORATORIYA ISHI 5-variant

DARAXTSIMON TUZILMALARNI TADQIQ QILISH

INDIVIDUAL TOPSHIRIQLAR

Binar daraxt tuzilmasini 2 bog’lamli ro’yxatlar yordamida shakllantirish. Standart amallarini(yangi tugun qo’shish, ekranga chiqarish, tozalash, tugun o'chirish va individual topshiriqni) funktsiyalar yordamida shakllantirish.

#include

using namespace std;

struct Node

{

int data;

struct Node *left, *right;

};

Node* newNode(int data)

{

Node *temp = new Node;

temp->data = data;

temp->left = temp->right = NULL;

return temp;

}

struct Node1 {

int data;

struct Node1* next;

};

Node* SortedMerge(Node* a, Node* b);

void push(struct Node1** head, int data)

{

struct Node1* newNode =

(struct Node1*)malloc(sizeof(struct Node1));

newNode->data = data;

newNode->next = (*head);

(*head) = newNode;

}

void printList(struct Node1* head)

{

while (head != NULL) {

printf("%d -> ", head->data);

head = head->next;

}

cout << "NULL" << endl;

}

Node1* SortedMerge(Node1* a, Node1* b);

void FrontBackSplit(Node1* source,

Node1** frontRef, Node1** backRef);

void MergeSort(Node1** headRef)

{

Node1* head = *headRef;

Node1* a;

Node1* b;

if ((head == NULL) || (head->next == NULL)) {

return;

}

FrontBackSplit(head, &a, &b);

MergeSort(&a);

MergeSort(&b);

*headRef = SortedMerge(a, b);

}

Node1* SortedMerge(Node1* a, Node1* b)

{

Node1* result = NULL;

if (a == NULL)

return (b);

else if (b == NULL)

return (a);

if (a->data <= b->data) {

result = a;

result->next = SortedMerge(a->next, b);

}

else {

result = b;

result->next = SortedMerge(a, b->next);

}

return (result);

}

void FrontBackSplit(Node1* source,

Node1** frontRef, Node1** backRef)

{

Node1* fast;

Node1* slow;

slow = source;

fast = source->next;

while (fast != NULL) {

fast = fast->next;

if (fast != NULL) {

slow = slow->next;

fast = fast->next;

}

}

*frontRef = source;

*backRef = slow->next;

slow->next = NULL;

}

int main()

{

Node *root = newNode(11);

root->left = newNode(23);

root->right = newNode(13);

root->left->left = newNode(4);

root->right->left = newNode(85);

root->right->right = newNode(7);

root->right->left->left = newNode(6);

root->right->left->right = newNode(17);

root->right->right->left = newNode(45);

root->right->right->right = newNode(410);

struct Node1* head = NULL;

cout << "Binar daraxt chapdan ongga: ";

queue q;

q.push(root);

while (!q.empty()) {

Node* current = q.front();

q.pop();

cout << current->data << " ";

push(&head, current->data);

if (current->left) q.push(current->left);

if (current->right) q.push(current->right);

}

MergeSort(&head);

cout << "\nSaralangan navbat : ";

printList(head);

return 0;

}


Download 139,85 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish