Muhammad al-Xorazmiy nomidagi Toshkent axborot texnologiyalari universitetining dasturiy injiniring fakulteti 316-21 guruhi 2-bosqich talabasi Rahmonov Akbarshohning Malumotlar tuzilmasidan fanidan bajargan ishi


Download 17.43 Kb.
Sana25.01.2023
Hajmi17.43 Kb.
#1118481
Bog'liq
Akbarshoh


Muhammad al-Xorazmiy nomidagi Toshkent axborot texnologiyalari universitetining dasturiy injiniring fakulteti 316-21 guruhi 2-bosqich talabasi Rahmonov Akbarshohning Malumotlar tuzilmasidan fanidan bajargan
ISHI.

O’qituvchi : G’iyosov Ulug’bek

Toshkent – 2022
17/Find the smallest element of the stack and then replace that element with 0.

#include
using namespace std;
void ReplaceElements(int arr[], int n)
{
int min_ele = arr[0];
arr[0] = -1;
for (int i = 1; i < n; ++i) {
if (min_ele < arr[i])
arr[i] = min_ele;

else if (min_ele >= arr[i]) {
int temp = arr[i];
arr[i] = min_ele;
min_ele = temp;
}
}
}
int main()
{
int arr[] = { 4, 5, 2, 1, 7, 6 };
int n = sizeof(arr) / sizeof(arr[0]);
ReplaceElements(arr, n);
for (int i = 0; i < n; ++i)
cout << arr[i] << " ";
return 0;
}
Download 17.43 Kb.

Do'stlaringiz bilan baham:




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