Algoritmlarni loyihalash fani bo`yicha Labaratoriya ishi-3 Bajardi
Download 120.64 Kb.
|
CAL lab 3
- Bu sahifa navigatsiya:
- Laboratoriya ishi №3. Murakkab malumotlar tuzilmalari: Ustuvor navbatlar.
- Bubble sort 500 1600 5000
- 2 – topshiriq
O`ZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI VA KOMMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI kafedrasi Algoritmlarni loyihalash fani bo`yicha Labaratoriya ishi-3 Bajardi: CAL018-L2- guruh talabasi Zokirov Farrux Tekshirdi: Murayeva Hodisaxon Laboratoriya ishi №3. Murakkab malumotlar tuzilmalari: Ustuvor navbatlar.
#include using namespace std; //random number void print( int x[], int n){ srand(time(0)); for (int i=0; i x[i]=(rand()%200);
}
} {
int temp = *xp; *xp = *yp; *yp = temp; }
// Bubble sort void bubbleSort( int arr[], int m) { int c,d,swap; time_t start,end; double tc; for(c=m;c>0;c--) { arr[c]=c+1; } start=clock(); for(c=0;c {
for(d=0;d if(arr[d]>arr[d+1]) {
swap=arr[d]; arr[d+1]=swap; } }
end=clock(); tc=(difftime(end,start)/CLOCKS_PER_SEC); printf("%lf | ",tc); } void Swap(int *Mas, int i) { int temp; temp=Mas[i]; Mas[i]=Mas[i-1]; Mas[i-1]=temp; } void ShakerSort(int Mas[], int Start, int N) { int Left, Right, i; clock_t st, end; st = clock(); Left=Start; Right=N-1; while (Left<=Right) { for (i=Right; i>=Left; i--) if (Mas[i-1]>Mas[i]) Swap(Mas, i); Left++;
for (i=Left; i<=Right; i++) if (Mas[i-1]>Mas[i]) Swap(Mas, i); Right--; } end = clock(); printf("%f | ", (double)(end - st) / CLOCKS_PER_SEC); } void quicksort(int l,int p,int *tab) { int i=l,j=p,x=tab[(l+p)/2],w; do {
i++;
} while (x {
j--;
if (i<=j) { w=tab[i]; tab[i]=tab[j]; tab[j]=w; i++; j--;
} } while (i<=j); if (l { quicksort(l,j,tab); } if (i
{ quicksort(i,p,tab); } }
int *tab = (int *)malloc(sizeof(int) * (2*n - 1)); size_t i; for (i = 0; i < n-1; i++) { tab[i] = tab[2*n-i-2] = i+1; } tab[n-1] = n; clock_t start = clock(); quicksort(0, 2*n-2, tab); clock_t finish = clock(); free(tab); return (double) (finish - start) / CLOCKS_PER_SEC; } int main() { int n=500, m=1600, p=5000; int a[n],b[m], c[p]; cout<<"\n________________________________________________________________________________________\n"; cout<<"\nSaralash nomi: || n="< cout<<"Bubble Sort || "; bubbleSort(a,n); bubbleSort(b,m); bubbleSort(c,p);
return 0; C++ (Python, Java) tilida quyida keltirilgan amallarni bajargan holda ustuvor navbat tashkil qiling: #include using namespace std;
void showpq(priority_queue {
priority_queue {
cout<< g.top()<<' '; g.pop(); } cout << '\n'; } int main() { priority_queue priority_queue pqueue2.push(3); pqueue2.push(5); pqueue2.push(1); pqueue2.push(7); pqueue2.push(9); pqueue2.push(3); pqueue2.push(2); int n; cout<<"navbat elementlari soni kiriting: "; cin>>n; int a[n]; for (int i=0; i cin>>a[i]; pqueue.push(a[i]);
}
cout<<"\nNavbatning berilishi: \n"; mark:
cout<<"\n\n____________MENYU____________ \n"; cout<<"1. Yangi element qo'shish \n"; cout<<"2. Eng katta elementni yechib olish \n"; cout<<"3. Berilgan qandaydir elementni yechib olish \n"; cout<<"4. Ikkita ustuvor navbatni birlashtiring \n"; int x;
cin>>x; cout< switch(x){
case 1:{ int b;
cout<<"biror bir son kiriting: "; pqueue.push(b); showpq(pqueue); break;
} case 2:{ cout<<"Navbatdagi eng katta element: "<
cout<<"Eng katta element yechib olingandan keyin: \n"; showpq(pqueue); break;
} case 3:{ pqueue.pop(); showpq(pqueue); break; }
cout<<"berilgan ikkinchi priority queue elementlari: \n"; showpq(pqueue2); while (!pqueue2.empty()) { pqueue.push(pqueue2.top()); pqueue2.pop(); } cout<<"\nIkkita navbatning qo'shilgani: \n"; showpq(pqueue); break;
} default: cout<<"Mavjud bo'lmagan buyruqni tanladingiz"; } cout<<"\nBosh menyuga qaytasizmi? (ha/yo'q)\n"; string s; cin>>s;
if(s=="ha"){ }else{ exit;
} } Download 120.64 Kb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling