Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- /* run this program using the console pauser or add your own getch, system("pause") or input loop */
- int *tw_tab (int r){
- int i;
- int *wsk;
- wsk=malloc(r*sizeof(int));
- for (i=0;i<r;i++){
- printf("t[%d]=",i+1);
- scanf("%d",&wsk[i]);
- }
- return wsk;
- }
- void BubbleSort(int *tab,int n)
- {
- int i,j,temp;
- for(j=n-1;j>0;j--){
- for(i=0;i<j;i++){
- if(tab[i]>tab[i+1]){
- temp=tab[i];
- tab[i]=tab[i+1];
- tab[i+1]=temp;
- }
- }
- }
- }
- void InsertSort(int *tab,int n)
- {
- int i,temp,j;
- for (i=0;i<n;i++){
- temp = tab[i];
- j=i-1;
- while (temp<=tab[j] && j>=0){
- tab[j+1]=tab[j];
- j--;
- } tab[j+1]=temp;
- }
- }
- void SelectionSort(int *tab,int n)
- {
- int i,j,temp;
- int max;
- for (i=n;i>0;i--){
- max=tab[i];
- for (j=0;j<=i;j++)
- {
- if (tab[j]>max){temp=max;max=tab[j];tab[j]=temp;}
- }tab[i]=max;
- }
- }
- void QuickSort(int *tab,int p,int k)
- {
- int x=tab[p];
- int i,j,temp;
- i=p;
- j=k;
- do
- {
- while (tab[i] < x) i++;
- while (tab[j] > x) j--;
- if (i<=j){
- temp=tab[i];
- tab[i]=tab[j];
- tab[j]=temp;
- ++i;
- --j;
- }
- }while(i<j);
- if(p<j) QuickSort(tab,p,j);
- if(k>i) QuickSort(tab,i,k);
- }
- int main(int argc, char *argv[]) {
- int n,temp;
- printf("ile elementów chcesz wprowadzić i posortować");
- scanf("%d",&n);
- int *tab_wsk;
- tab_wsk=tw_tab(n);
- //BubbleSort(tab_wsk,n);
- //InsertSort(tab_wsk,n);
- //SelectionSort(tab_wsk,n);
- QuickSort(tab_wsk,0,n);
- int i;
- for(i=0;i<n;i++)
- {
- printf("%d \n",tab_wsk[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement