#include
#include
#include
using namespace std;
/*******************************************/
int max = 5000000;
int maxlen = 25;
int limit = 20;
typedef struct{
int info1;
int info2;
} ElemType;
ElemType* stos = new ElemType[maxlen]; //stos
int* tab = new int[max+1];
int count = 0;
/*******************************************/
bool empty(int s){
if (s==0) return true;
else return false;
}
void init(int& s){
s = 0;
stos[s].info1 = 0;
stos[s].info2 = 0;
}
inline void pop(int& s){
s--; //bez sprawdzania
}
inline void push(int& s, int x, int y){
s++;
stos[s].info1 = x;
stos[s].info2 = y;
}
inline ElemType top(int s){
return stos[s];
}
int partition (int* A, int L, int R){
int schowek;
int m=rand()%(R-L)+L;
int x=A[m];
do {
while (A[L] < x) L++;
while (x < A[R]) R--;
if (L<=R) {
int schowek = A[L];
A[L] = A[R];
A[R] = schowek;
L++; R--;
}
} while (L<=R) ;
return (L-1);
}
/*******************************************/
void quickSortStack (int* A, int l, int r){
int j;
int s; //stos
init(s);
while ((l count++; if (l j = partition (A,l,r); if ((j-l)<(r-j)){ push(s,j+1,r); r = j; }else{ push(s,l,j); l = j+1; } }else{ l = top(s).info1; r = top(s).info2; pop(s); } } } /*****************************************/ int main(){ int proby; int n; srand((unsigned)time(NULL)); printf ("Wpisz ilosc zestawow danych: "); scanf("%d", &proby); int i = 1; while (i count = 0; printf ("Wpisz ilosc elementow tablicy: "); scanf("%d",&n); int j = 1; while (j printf ("Wpisz %d element tablicy: ",j); scanf("%d", &tab[j]); j++; } quickSortStack(tab,1,n); j = 1; printf ("Wynik: "); while (j printf("%d ",tab[j]); j++; } printf(""); i++; } return 0; }