Tekshurdi: zaripov fazilbek


Download 263.52 Kb.
Sana18.12.2022
Hajmi263.52 Kb.
#1028553

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 gq)
{
queue g = gq;
while (!g.empty()) {
cout << ' ' << g.front();
g.pop();
}
cout << '\n';
}
int main()
{
queue gquiz;
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
6. N o’lchamli sonli qiymatdagi to’plam berilgan. Bir bog’lamli ro’yhat ko’rinishida stek yaratilsin va to’plam elementlari stekga qo’shilsin. Stek cho’qqisidan 1 ta element olinsin va ekranga chiqarilsin. Stekga yangi 1 ta element qo’shilsin. Stek barcha elementlari ekranga chiqarilsin.


#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