Mavzu: Bog’langan ro’yhat. Ikkala bog’langan ro’yxat bilan ishlash


void append(struct Node** head_ref, int new_data)



Download 35,35 Kb.
bet6/6
Sana31.12.2021
Hajmi35,35 Kb.
#247747
1   2   3   4   5   6
Bog'liq
15-laboratoriya ishi

void append(struct Node** head_ref, int new_data)
{
struct Node* new_node = (struct Node*)malloc(sizeof(struct Node));
struct Node* last = *head_ref; /* used in step 5*/
new_node->data = new_data;
new_node->next = NULL;
if (*head_ref == NULL) {
new_node->prev = NULL;
*head_ref = new_node;
return;
}
while (last->next != NULL)
last = last->next;
last->next = new_node;
new_node->prev = last;
return;
}
Yuqoridagi barcha jarayonlar:
#include
#include
struct Node {
int data;
struct Node* next;
struct Node* prev;
};
void push(struct Node** head_ref, int new_data)
{
struct Node* new_node = (struct Node*)malloc(sizeof(struct Node));
new_node->data = new_data;
new_node->next = (*head_ref);
new_node->prev = NULL;
if ((*head_ref) != NULL)
(*head_ref)->prev = new_node;
(*head_ref) = new_node;
}
void insertBefore(struct Node** head_ref, struct Node* next_node, int
new_data)
{
if (next_node == NULL) {
printf("the given next node cannot be NULL");
return;
}
struct Node* new_node = (struct Node*)malloc(sizeof(struct Node));
new_node->data = new_data;
new_node->prev = next_node->prev;
next_node->prev = new_node;
new_node->next = next_node;
if (new_node->prev != NULL)
new_node->prev->next = new_node;
else
(*head_ref) = new_node;
}
void printList(struct Node* node)
{
struct Node* last;
printf("\nTraversal in forward direction \n");
while (node != NULL) {
printf(" %d ", node->data);
last = node;
node = node->next;
}
printf("\nTraversal in reverse direction \n");
while (last != NULL) {
printf(" %d ", last->data);
last = last->prev;
}
}
int main()
{
struct Node* head = NULL;
push(&head, 7);
push(&head, 1);
push(&head, 4);
insertBefore(&head, head->next, 8);
printf("Created DLL is: ");
printList(head);
getchar();
return 0;
}
Topshiriqlar:

12. Doubly linked list (ikki bog’langan ro’yxat) asosida ixtiyoriy N
qiymatdagi sonlar to’plami kiritilsin. Dasturning oxirgi qismiga yangi
node kiritilsin va natijalar ekranga chiqarilsin.
Dastur kodi:

#include

#include

struct Node {

int data;

struct Node* next;

struct Node* prev;

};

void push(struct Node** head_ref, int new_data)

{

struct Node* new_node = (struct Node*)malloc(sizeof(struct Node));

new_node->data = new_data;

new_node->next = (*head_ref);

new_node->prev = NULL;

if ((*head_ref) != NULL)

(*head_ref)->prev = new_node;

(*head_ref) = new_node;

}

void insertBefore(struct Node** head_ref, struct Node* next_node, int

new_data)

{

if (next_node == NULL) {

printf("the given next node cannot be NULL");

return;

}

struct Node* new_node = (struct Node*)malloc(sizeof(struct Node));

new_node->data = new_data;

new_node->prev = next_node->prev;

next_node->prev = new_node;

new_node->next = next_node;

if (new_node->prev != NULL)

new_node->prev->next = new_node;

else

(*head_ref) = new_node;

}

void printList(struct Node* node)

{

struct Node* last;

printf("\nTraversal in forward direction \n");

while (node != NULL) {

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

last = node;

node = node->next;

}

printf("\nTraversal in reverse direction \n");

while (last != NULL) {

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

last = last->prev;

}

}

int main()

{

struct Node* head = NULL;

push(&head, 11);

push(&head, 5);

push(&head, 16);

insertBefore(&head, head->next, 10);

printf("Created DLL is: ");

printList(head);

getchar();

return 0;

}

Natija:



Xulosa:

Men bu laboratoriya mashg’ulotida mavzuga oid nazariy va amaliy bilimlarimni mustahkamladim. Avvalo algoritmlar tuzdik so’ngra ishni C++ dasturlash muhitida davom ettirdik. Turli xil amallarni bajarib kerakli natijalarni oldim.



Foydalanilgan adabiyotlar:
1. Алфред В. Ахо., Джон Э. Хопкрофт, Джефри Д. Ульман. Структура
данных и алгоритмы. //Учеб.пос., М.: Изд.дом: "Вильямс", 2000, — 384 с.
2. Adam DrozdekData structures and algorithms in C++. Fourth edition.
Cengage Learning, 2013.
3. Бакнелл Джулиан М. Фундаментальные алгоритмы и структуры
данных в Delphi//СПб: ООО «ДиаСофтЮП», 2003. 560с.
4. Narzullaev U.X., Qarshiev A.B., Boynazarov I.M. Ma’lumotlar tuzilmasi
va algoritmlar. //O’quv qo’llanma. Toshkent: Tafakkur nashriyoti, 2013 y. – 192
5. Лойко В.И. Структуры и алгоритмы обработки данных. Учебное
пособие для вузов. - Краснодар: КубГАУ. 2000. - 261 с., ил.
Download 35,35 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6




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