void QuickSort::sortX(RGRID *array, unsigned *idx, int first,int last) { if(first<last){ int low,high;float list_separator; RGRID temp; unsigned tmpidx; low = first; high = last; list_separator = array[(first+last)/2].pos.x; do { while(array[low].pos.x<list_separator) low++; while(array[high].pos.x>list_separator) high--; if(low<=high) { temp = array[low]; tmpidx = idx[low]; idx[low] = idx[high]; array[low++] = array[high]; idx[high] = tmpidx; array[high--]=temp; // //idx[low++] = idx[high]; //idx[high--] = tmpidx; } }while(low<=high); if(first<high) sortX(array, idx, first,high); if(low<last) sortX(array, idx, low,last); } }
void QuickSort::sortX(PosAndId *array,int first,int last) { if(first<last){ int low,high;float list_separator; PosAndId temp; low = first; high = last; list_separator = array[(first+last)/2].pos.x; do { while(array[low].pos.x<list_separator) low++; while(array[high].pos.x>list_separator) high--; if(low<=high) { temp = array[low]; array[low++] = array[high]; array[high--]=temp; } }while(low<=high); if(first<high) sortX(array,first,high); if(low<last) sortX(array,low,last); } }
int main(){ struct Node node9 = {9, NULL}; struct Node node8 = {8, &node9}; struct Node node7 = {7, &node8}; struct Node node6 = {6, &node7}; struct Node node5 = {5, &node6}; struct Node node4 = {4, &node5}; struct Node node3 = {13, &node4}; struct Node node2 = {12, &node3}; struct Node node1 = {1, &node2}; printNodes(&node1); sortX(&node1, 7); printNodes(&node1); return 0; }
bool Statistics::topX(ListBase<Product>* List,int _num, ListBase<Product>* Result){ if(List->isEmpty()||_num==0) return false; //ListBase<Product>* Result=new ListDA<Product>(); sortX(List,Result,_num); /* if (Sorted->isEmpty()) return false; double revenue1,revenue2; for(int i=0;i<_num && i<Sorted->getLength();i++) { if(i<((Sorted->getLength())-1)) { revenue1=Sorted->retrieveItem(i)->get_sale()*Sorted->retrieveItem(i)->get_price(); revenue2=Sorted->retrieveItem(i+1)->get_sale()*Sorted->retrieveItem(i+1)->get_price(); if (revenue1==revenue2) _num++;} Result->addItem(Sorted->retrieveItem(i)); }*/ if (Result->isEmpty()) return false; /*vector<Product> ListSort; for(int d=0; d<List->getLength(); d++){ Item=List->retrieveItem(d); ListSort.push_back(*Item); } sort(ListSort, List->getLength()); for(int i=0;i<_num;i++) {Item=&ListSort[i]; Result->addItem(Item);}*/ //for(int k=0; k<_num; k++){ // Result->appendItem(ListSort[k]); /*}*/ return true; }