Ma’lumotlar tuzilmasi va algoritmlar fanidan topshiriq bo’yicha hisobot
Topshiriq: 2
Guruh : SWD019-2
Talaba: MARDONOV SEROBBOY
1-vazifa. N o’lchamli massiv berilgan. Massiv elementlarini pufakchali saralash usulida
saralang.
Yechimi:
#include ; using namespace std; int main () { int n, i, arr[5], j, temp; cout << "Enter the Size (max. 5): "; cin >> n; cout << "Enter " << n << " Numbers: "; for (i = 0; i < n; i++) cin >> arr[i]; cout << "\n Sort Technique(pufakcha usuli)..\n"; for (i = 0; i < (n - 1); i++) { for (j = 0; j < (n - i - 1); j++) { if (arr[j] > arr[j + 1]) { temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; } } } cout << "\nyangi Array is: \n"; for (i = 0; i < n; i++) cout << arr[i] << " "; cout << endl; return 0;
}
2.STL kutubxonasidan unordered_map orqali xesh jadval yarating va n sonli
tipdagi element bilan to’ldiring. To’plamdan foydalanuvchi kiritgan elementni
qidirib topish va ekranda chiqarish dasturini yozing.
// C++ program to add two numbers represented by Linked
// Lists using Stack
#include using namespace std;
class Node {
public:
int data;
Node* next;
};
Node* newnode(int data)
{
Node* x = new Node();
x->data = data;
return x;
}// C++ program to demonstrate
// functionality of unordered_map
#include #include using namespace std;
// Driver code
int main()
{
// Declaring umap to be of
// type key
// will be of STRING type
// and mapped VALUE will
// be of int type
unordered_map<string, int> umap;
for (auto x : umap)
cout << x.first << " " <<
x.second << endl;}
3 . N o’lchamli to’plam berilgan. Bir bo’glamli ro’yhat hosil qilish. Ro’yhatga to’plam elementlarini qo’shish. Foydalanuvchi kiritgan elementni ro’yhatga qo’shish. Ro’yhatni ekranga chiqarish.