27-variant dastur kodi: #include using namespace std; struct node { int info; node* link = null; node {} node


Download 31.06 Kb.
Sana20.12.2022
Hajmi31.06 Kb.
#1035065


Muhammad Al-Xorazmiy nomidagi Toshkent Axborot Texnologiyalari Universiteti

Ma’lumotlar tuzilmasi va algoritmlar
3-amaliy ishi
Bajardi: SWD027-1 guruhining talabasi
Zayniddinov Abbos
Tekshirdi: Axmadjonov Islomjon.

Toshkent 2022


27-VARIANT
Dastur kodi:

#include
using namespace std;

struct node {
int info;
node* link = NULL;
node() {}
node(int a) : info(a){}
};

void deleteNode(node*& head, int val)
{
if (head == NULL) {
cout << "Element roʻyxatda yoʻq\n";
return;
}

if (head->info == val) {
node* t = head;
head = head->link;
delete (t);
return;
}
deleteNode(head->link, val);
}

void push(node*& head, int data)
{
node* newNode = new node(data);
newNode->link = head;
head = newNode;
}

void print(node* head)
{
if (head == NULL and cout << endl) return;
cout << head->info << ' ';
print(head->link);
}

int main()
{
node* list = NULL;
int n, max_val = INT_MIN;
cout << "Ro'yxat uzunligini kiriting : ";
cin >> n;
for(int i = 0, x; i < n; i ++){
cin >> x;
push(list, x);
if(x > max_val){
max_val = x;
}
}
cout << "Dastlabki ro'yxat : ";
print(list);
deleteNode(list, max_val);
printf("O'zgargan ro'yxat : ");
print(list);
return 0;
}Dastur natijasi:


Download 31.06 Kb.

Do'stlaringiz bilan baham:




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