Function to sort a data set inplace.
BOOL Data_sort( Dataset * pdsData, BOOL bDescending = FALSE, BOOL bMissingAsMin = FALSE )
If successful returns TRUE and a sorted dataset otherwise returns FALSE.
EX1
// This is a self contained sample program for the function Data_sort. // It demonstrates a simple call of the function, and shows how to // sort a dataset by replacing the input dataset with the sorted one. // The sample data is created at the beginning of the program. // To run the program, enter the following command in the Script window: // Data_sort_ex1 // This will print a message like following: // Applying Data_sort on Data2_A succedded. (updated the dataset directly) // Simple call with defaults: Ascending & Missing as Largest // void Data_sort_ex1() { BOOL success; Worksheet wks; wks.Create(); String wksName=wks.GetPage().GetName(); Dataset myInDs(wks,0); String strInDsName = myInDs.GetName(); Dataset myOrg(wks,1); // Back up dataset of original wks.Columns(1).SetName("Original"); //******* Create sample data ***************** myInDs.SetSize(7); myOrg.SetSize(7); myInDs[0]=0.097; myOrg[0]=myInDs[0]; myInDs[1]=0.41256; myOrg[1]=myInDs[1]; myInDs[2]=NANUM; myOrg[2]=myInDs[2]; myInDs[3]=0.47304; myOrg[3]=myInDs[3]; myInDs[4]=NANUM; myOrg[4]=myInDs[4]; myInDs[5]=0.64529; myOrg[5]=myInDs[5]; myInDs[6]=0.44514; myOrg[6]=myInDs[6]; //******** End of Sample Data Creation ******* success = Data_sort(&myInDs); // Demonstration of Data_sort if(success) printf("Applying Data_sort on %s succedded. (updated the dataset directly)\n" " Simple call with defaults: Ascending & Missing as Largest\n",strInDsName); else printf("Error: Data_sort failed.\n"); }
EX2
// This is a self contained sample program for the function Data_sort. // It demonstrates the function call with its parameters, and shows how // to sort a dataset without modifying itself by sorting a copied // temporary dataset. // The sample data is created at the beginning of the program. // To run the program, enter the following command in the Script window: // Data_sort_ex2 // This will print a message like following: // Applying Data_sort on Data4_A succedded. (result in the temporary dataset) // Function call with specifications: Ascending Flag=0 & Missing_as_Largest Flag=1 // Number of Missing Values = 2 // void Data_sort_ex2() { int i,iMissing; BOOL success; Worksheet wks; wks.Create(); Dataset myInDs(wks,0); String strInDsName = myInDs.GetName(); //******* Create sample data ***************** myInDs.SetSize(7); myInDs[0]=0.097; myInDs[1]=0.41256; myInDs[2]=NANUM; myInDs[3]=0.47304; myInDs[4]=NANUM; myInDs[5]=0.64529; myInDs[6]=0.44514; BOOL ASCENDING_FLAG = FALSE; BOOL NANUM_AS_LARGEST_FLAG = TRUE; //******** End of Sample Data Creation ******* Dataset mySortDs(myInDs); // Create a temporary copy of original data mySortDs.SetSize(myInDs.GetSize()); success = Data_sort(&mySortDs,ASCENDING_FLAG,NANUM_AS_LARGEST_FLAG); // Demonstration of Data_sort if(success) { printf("Applying Data_sort on %s succedded. (result in the temporary dataset)\n" " Function call with specifications: Ascending Flag=%d & Missing_as_Largest Flag=%d\n", strInDsName,ASCENDING_FLAG,NANUM_AS_LARGEST_FLAG); iMissing=0; for(i=0; i<7; i++) { if(mySortDs[i]==NANUM) iMissing++; else break; // NANUMs grouped at top, and break immediately when found not NANUM. } printf(" Number of Missing Values = %d\n",iMissing); } else printf("Error: Data_sort failed.\n"); }
Function to sort a data set inplace.
origin.h