6-amaliy mashg’ulot


Download 0.59 Mb.
bet2/3
Sana23.12.2022
Hajmi0.59 Mb.
#1045573
1   2   3
Bog'liq
640-21 Mo`moniv Anvarjon 6-10........

8-amaliy mashg’ulotda savollar kamligi uchun men 8-raqamdagi savolni ishladim savolar soni 22 ta ekan men 30 da turaman:

8. Doubly linked list (ikki bog’langan ro’yxat) asosida ixtiyoriy N qiymatdagi sonlar to’plami kiritilsin. Dasturning o’rta qismiga yangi node kiritilsin va natijalar ekranga chiqarilsin


Kod:
#include


#include
struct Node {
int data;
struct Node* next;
};

void printList(struct Node* n)


{
while (n != NULL) {
printf(" %d ", n->data);
n = n->next;
}
}

int main()


{
struct Node* head = NULL;
struct Node* second = NULL;
struct Node* third = NULL;
head = (struct Node*)malloc(sizeof(struct Node));
second = (struct Node*)malloc(sizeof(struct Node));
third = (struct Node*)malloc(sizeof(struct Node));
head->data = 1;
head->next = second;
second->data = 2;
second->next = third;
third->data = 3;
third->next = NULL;

printList(head);


return 0;
}

Natija:




9-amaliy mashg’ulot da savollar kamligi uchun men 10-raqamdagi savolni ishladim savolar soni 20 ta ekan men 30 da turaman:

10. Massivni stack asosida qo’llagan xolda do while operatorini ichida switch() case dan foydalanib 1.push() – stackga ma’lumot qo’shish; 2. pop() - stackdan ma’lumot olib tashash; 3.display() – ekranga ma’lumot chiqarish; 4. exit – chiqish buyruqlari bajarilsin


Kod: #include
#include
using namespace std;
void showq(queue gq)
{
queue g = gq;
while(!g.empty())
{
cout << '\t'<g.pop();
}
cout << '\n';
}

int main()


{
queue gquiz;
gquiz.push(10);
gquiz.push(20);
gquiz.push(30);
cout << "Kiritilganlar : ";
showq(gquiz);
cout << "\ngquiz.size() : "<< gquiz.size();
cout << "\ngquiz.back() : "<< gquiz.back();
gquiz.pop();
showq(gquiz);

for(auto i = gquiz.front(); i != gquiz.back(); i++)


{
cout<< i <<" ";
}
return 0;
}




Download 0.59 Mb.

Do'stlaringiz bilan baham:
1   2   3




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