Muhammad Al-Xorazmiy nomidagi
Toshkent axborot texnologiyalari unversitetining
Kompyuter injinering fakuteti 2-kurs 211-22 guruh talabasi Haydarov Quvonchbekning Malumotlar tuzilmasi va algoritmlash fanidan amaliy ishi.
Toshkent 2023
Tekshirdi: Djangazova Kumriniso Abdulvoxabovna
Bajardi : Haydarov Quvonchbek
6. N o’lchamli to’plam berilgan. Bir bo’glamli ro’yhat hosil qilish. Ro’yhatga to’plam elementlarini qo’shish. Foydalanuvchi kiritgan indeksdagi elementni o’chirish. Ro’yhatni ekranga chiqarish.
template void Delete(list& myList, int index)
{
if (index >= 0 && index < myList.size()) {
auto it = myList.begin();
advance(it, index);
myList.erase(it);
cout << "Yangi ro'yhatning holati: ";
for (int elem : myList) {
cout << elem << " ";
}
cout << endl;
} else {
cout << "Noto'g'ri indeks kiritildi." << endl;
}
}
int main() {
list myList;
int n;
cin >> n;
cout << "Ro'yxat elementlarini kiriting: " << endl;
int x;
for(int i=0; icin >> x;
myList.push_back(x);
}
cout << "Ro'yhatning hozirgi holati: ";
for (int elem : myList) {
cout << elem << " ";
}
cout << endl;
int indexToDelete;
cout << "O'chirish uchun indeksni kiriting: ";
cin >> indexToDelete;
Delete(myList, indexToDelete);
return 0;
}
6. N ta elementdan tashkil topgan navbat berilgan. Navbatning oxiridagi elementiga teng barcha elementlarni o’chiring
#include #include using namespace std;
int main() {
queue myQueue;
queue result;
int n;
cin >> n;
cout << "Navbat elementlarini kiriting: ";
int x;
for(int i=0; icin >> x;
myQueue.push(x);
}
int targetElement = myQueue.back(); // Oxirgi elementni olish
while (!myQueue.empty()) {
if(myQueue.front() != targetElement){
result.push(myQueue.front());
}
myQueue.pop();
}
cout << "Yangilangan navbat: " << endl;
while (!result.empty()) {
cout << result.front() << endl;
result.pop();
}
return 0;
}