}
talaba[n];
for(int i=0;i
cout<
cout<
int low = 0,hi = n-1,search=-1,q=0;
string key;
cout<<"Qidirilayotgan talabani fish ni kiriting:";cin>>key;
while(low<=hi){
int mid = (low + hi) / 2;
q++;
if (key == talaba[mid].fio){
search = mid;
break;
}
if (key < talaba[mid].fio)
hi = mid - 1;
else low = mid + 1;
}
if(search!=-1) cout<<"qidirilayotgan el "<
else {cout<
return 0;
}
while(talaba[search-1].fio==key) search--;
while(talaba[search].fio==key) {
cout<
search++; }}
A[100] masssiv elementlarini rand() funktsiyasi yordamida tasodifiy sonlar bilan to’ldiring va saralangan massiv elementlarini o’sish tartibida chiqaring (Selection Sort saralash algoritmi orqali).
#include
#include
#include
using namespace std;
int main()
{
srand(time(0));
int uzunligi=100;
int son[uzunligi];
for (int i = 0; i < uzunligi; i++)
son[i]=rand()%100;
for(int boshi=0;boshi
{
int kichik=boshi;
for(int qadam=boshi+1;qadam
{
if(son[qadam]
kichik=qadam;
}
int temp=son[boshi];
son[boshi]=son[kichik];
son[kichik]=temp;
}
for(int index=0;index
cout<
return 0;
}
10.B[100] masssiv elementlarini rand() funktsiyasi yordamida tasodifiy sonlar bilan to’ldiring va saralangan massiv elementlarini kamayish tartibida joylashtiring. (Selection Sort saralash algoritmi orqali).
#include
#include
#include
using namespace std;
int main()
{
srand(time(0));
int uzunligi=100;
int son[uzunligi];
for (int i = 0; i < uzunligi; i++)
son[i]=rand()%100;
for(int boshi=0;boshi
{
int kichik=boshi;
for(int qadam=boshi+1;qadam
{
if(son[qadam]
kichik=qadam;
}
int temp=son[boshi];
son[boshi]=son[kichik];
son[kichik]=temp;
}
for(int index=uzunligi-1;index>=0;index--)
cout<
return 0;
}
11.Talabalar ro’yxati berilgan, ushbu ro’yxatni talabalar familiyasi bo’yicha alifbo tartibida saralang. (Selection Sort saralash algoritmi orqali).
#include
#include
#include
using namespace std;
int main()
{
int z = 0;
string name[] = {"jonibek", "bobur", "diyor", "toxir", "charos", "nomi", "sharif", "marat", "aziz", "may", "zebo", "zokir", "angel", "galaktika"};
sort(name[0],name[z]);
for(int y = 0; y < z; y++)
{cout << name[z] << endl; }
return 0;}
12. Talabalar ro’yxati berilgan, ularni yoshi bo’yicha o’sish tartibida saralang. (Selection Sort saralash algoritmi orqali).
#include
using namespace std;
void swap(int *xp, int *yp)
{ int temp = *xp; *xp = *yp; *yp = temp;}
void selectionSort(int arr[], int n)
{int i, j, min_idx;
// Saralanmagan subarrayning ketma-ket chegarasi
for (i = 0; i < n-1; i++)
{// Saralanmagan massivda minimal elementni toping
min_idx = i;
for (j = i+1; j < n; j++)
if (arr[j] < arr[min_idx])
min_idx = j;
// Topilgan minimal elementni birinchi element bilan almashtiring
swap(&arr[min_idx], &arr[i]);}}
/* Bir qatorni bosib chiqarish funktsiyasi */
void printArray(int arr[], int size)
{int i;
for (i=0; i < size; i++)
cout << arr[i] << " ";cout << endl;
}
// Yuqoridagi funktsiyalarni sinab ko'rish uchun dasturi tanasi
int main()
{int arr[] = {20, 25, 27, 22, 30};
int n = sizeof(arr)/sizeof(arr[0]);
selectionSort(arr, n);
cout << "Saralangan qator: \n";
printArray(arr, n);
return 0;}
13. Respublikamizdagi viloyatlar maydonini o’sish tartibida joylashtiring. (Bubble Sort saralash algoritmi orqali).
#include
using namespace std;
void swap(double *xp, double *yp)
{int temp = *xp; *xp = *yp; *yp = temp; }
// bubble sort amalga oshiriladigan funktsiya
void bubbleSort(double arr[], int n)
{ int i, j;
for (i = 0; i < n-1; i++)
// So'nggi i elementlari allaqachon mavjud
for (j = 0; j < n-i-1; j++)
if (arr[j] > arr[j+1])
swap(&arr[j], &arr[j+1]); }
/* chiqarish funktsiyasi */
void printArray(double arr[], int size)
{ int i;
for (i = 0; i < size; i++)
cout << arr[i] << " "; cout << endl;
}
// Tana qismi
int main()
{ double arr[] = {166.59, 6.76, 110.99, 4.3, 21.21, 28.57, 4.28,40.32,7.44,16.77,20.1,15.25,6.05};
int n = sizeof(arr)/sizeof(arr[0]);
bubbleSort(arr, n);
cout<<"Sorted array: \n";
printArray(arr, n);
return 0; }
14. Respublikamizdagi viloyatlar maydonini kamayish tartibida joylashtiring. (Bubble Sort saralash algoritmi orqali).
#include
using namespace std;
void swap(double *xp, double *yp)
{int temp = *xp; *xp = *yp; *yp = temp; }
// bubble sort amalga oshiriladigan funktsiya
void bubbleSort(double mass[], int n)
{ int i, j;
for (i = 0; i < n-1; i++)
// So'nggi i elementlari allaqachon mavjud
for (j = 0; j < n-i-1; j++)
if (mass[j] > mass[j+1])
swap(&mass[j], &mass[j+1]); }
/* chiqarish funktsiyasi */
void printMassay(double mass[], int size)
{for(int i=size-1;i>=0;i--)
cout<
// Tana qismi
int main()
{ double mass[] = {166.59, 6.76, 110.99, 4.3, 21.21, 28.57, 4.28,40.32,7.44,16.77,20.1,15.25,6.05};
int n = sizeof(mass)/sizeof(mass[0]);
bubbleSort(mass, n);
cout<<"Sorted massay: \n";
printMassay(mass, n);
return 0; }
15.Guruhdagi talabalar smestrdagi olgan baholariga qarab o’sish tartibida chop eting. (Bubble Sort saralash algoritmi orqali).
#include
#include
#include
// 2 ta sohaga ega bo'lgan odam
struct Student { char* FISH; char ball;};
// taqqoslash uchun qoidalarni o'rnatish
// o'quvchilarni ball asosida saralash
int comparator(const void* p, const void* q)
{return (((struct Student*)p)->ball - ((struct Student*)q)->ball);}
int main()
{int i = 0, n = 5;
struct Student massiv[n];
// Get the students data
massiv[0].FISH = "Isomiddinov";
massiv[0].ball = 70;
massiv[1].FISH = "Aslanov";
massiv[1].ball = 65;
massiv[2].FISH = "Baxriyev";
massiv[2].ball = 75;
massiv[3].FISH = "Tilavov";
massiv[3].ball = 80;
massiv[4].FISH = "Berdiyev";
massiv[4].ball = 98;
// Turli xil tuzilmani chop eting
printf("Talabalarning FISH va ballari:\n");
for (i = 0; i < n; i++) {
printf("FISH = %s, Ball = %d \n",
massiv[i].FISH, massiv[i].ball);
}
// belgilangan taqqoslagich asosida
qsort(massiv, n, sizeof(struct Student), comparator);
printf("\n\nSarlangan talabalar ballari:\n");
for (i = 0; i < n; i++) {
printf("FISH = %s, Ball = %d \n",
massiv[i].FISH, massiv[i].ball); }
return 0;
}
16. Karim N yoshda, Salim M yoshda, Jasur K yoshda. Siz bu aka-ukalarning yoshini o’sish tartibida chop eting. (Quick Sort saralash algoritmi orqali).
Do'stlaringiz bilan baham: |