#include "TGraph.h" void TestGraphSort() { // This program sorts the following 9 numbers, in groups of 3. //Int_t m; Float_t x[9]={3.0, 2.0, 1.0, 6.0, 5.0, 4.0, 9.0, 8.0, 7.0}; Float_t y[9]={30.0,20.0,10.0,60.0,50.0,40.0,90.0,80.0,70.0}; Double_t *px, *py; // Tgraph::Sort() works ok in the following indivisual calls. TGraph *graph=new TGraph(9,x,y); graph->Sort(&TGraph::CompareX,kTRUE,0,2); graph->Sort(&TGraph::CompareX,kTRUE,3,5); graph->Sort(&TGraph::CompareX,kTRUE,6,8); px=graph->GetX(); py=graph->GetY(); for (Int_t i=0; i<9;i++) printf("x=%2.1f y=%2.1f \n ",*(px+i),*(py+i)); print("\n"); //However, if TGraph::Sort() is called in a while-loop or in an if-loop (as shown below), segmentation occurs if run in interpreted mode: // >>.x TestGraphSOrt.c // It seems to run OK in compiled mode: // >>.x TestGraphSort.c+ TGraph *graph1=new TGraph(9,x,y); for(Int_t m=0;m<3;m++){ graph1->Sort(&TGraph::CompareX,kTRUE,3*m,3*(m+1)-1); } px=graph1->GetX(); py=graph1->GetY(); for (Int_t i=0; i<9;i++) printf("x=%2.1f y=%2.1f \n ",*(px+i),*(py+i)); }