Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- #include <cstdio>
- #include <cstdlib>
- #include <conio.h>
- using namespace std;
- void wczyt(double T[], int n)
- {
- for (int i=0; i<n; i++)
- {
- cout <<"podaj "<<i+1<<" liczbe"<<endl;
- cin >>T[i];
- }
- }
- void Sortowaniem( double T[], int left, int right )
- {
- int pom;
- int i = left;
- int j = right;
- int x = T[( left + right ) / 2 ];
- do
- {
- while( T[ i ] > x )
- i++;
- while( T[ j ] < x )
- j--;
- if( i <= j )
- {
- pom = T[i];
- T[i]=T[j];
- T[j]=pom;
- i++;
- j--;
- }
- } while( i <= j );
- if( left > j ) Sortowaniem( T, left, j );
- if( right < i ) Sortowaniem( T, i, right );
- }
- void Sortowanie( double T[], int left, int right )
- {
- int pom;
- int i = left;
- int j = right;
- int x = T[( left + right ) / 2 ];
- do
- {
- while( T[ i ] < x )
- i++;
- while( T[ j ] > x )
- j--;
- if( i <= j )
- {
- pom = T[i];
- T[i]=T[j];
- T[j]=pom;
- i++;
- j--;
- }
- } while( i <= j );
- if( left < j ) Sortowanie( T, left, j );
- if( right > i ) Sortowanie( T, i, right );
- }
- int main ()
- {int i,j;
- int n;
- for (;;)
- {
- int wybor;
- cout <<" witaj w programie sortujacym"<<endl;
- cout <<" ile elementów chcesz posortowac ?"<<endl;
- cin>>n;
- double T[n];
- wczyt (T, n);
- cout <<" %%%%%%%%%%%%%% MENU %%%%%%%%%%%"<<endl;
- cout <<" 1. sortowanie rosnaco"<<endl;
- cout <<" 2. sortowanie malejaco"<<endl;
- cout <<" 3. zamkniecie programu"<<endl;
- wybor =getch();
- switch (wybor)
- {
- case'1':
- Sortowanie (T,0,n-1);
- cout <<" Po posortowaniu rosnaco: "<<endl;
- for (int i=0;i<n;i++)
- {
- cout <<"T["<<i<<"]="<<T[i]<<endl;
- };
- break;
- case '2':
- Sortowaniem(T,0,n-1);
- cout <<" Po posortowaniu malejaco: "<<endl;
- for (int i=0;i<n;i++)
- {
- cout <<"T["<<i<<"]="<<T[i]<<endl;
- };
- break;
- case '3':
- exit (0);
- break;
- default:
- cout<<"nie matakiej opcji"<<endl;
- };
- break;
- }
- getchar (); getchar();
- system ("cls");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement