Salve a tutti 
difftime(stop, start) ; // il delta è sempre zero perchè la risoluzione (la grana) è in secondi
se stai sotto UNIX e accedi a POSIX puoi usare la gloriosa gettimeofday
05/11/2023 - oregon ha scritto:
Intanto si scrive “crash”, in secondo luogo quando posti il codice sul forum devi formattarlo usando il tasto <>
Per quanto riguarda il problema, prima di usare ogni elemento i-esimo del vettore, devi allocare lo spazio per la struttura e assegnare il relativo puntatore al puntatore i-esimo
devi allocare ogni singolo elemento dell'array di puntatori altrimenti … non funge
POICHE' SONO MOLTO PARANOICO , ho  messo sotto try and catch l'operatore new
puoi anche scrivere,  risulta un po' grezza come soluzione ma meglio di niente:
	// alloc memory
	for (int i = 0; i<NUM_ELE; i++){
		vP[i] = nullptr;
		vP[i] = new t_elemento;
		if (vP[i] == nullptr){
			cout << "Elemento :" << i << " - non allocato " << endl;
			return EXIT_FAILURE;
		}
	}
#include <iostream>
#include <string>
//#include <ctime>
#include <cstdlib>
#include <exception>
#include <sys/time.h>
using namespace std;
const int NUM_ELE = 1000;
struct t_elemento{
	int n;
	double v[1000];
};
t_elemento *vP[NUM_ELE];
int main(){
	//time_t start = time(0), stop = time(0);
	struct timeval t1, t2;
	srand(10);
	// alloc memory
	for (int i = 0; i<NUM_ELE; i++){
		try{
			vP[i] = new t_elemento();
		}
		catch (exception& e){
			cout << "Elemento :" << i << " non allocato - Standard exception: " << e.what() << endl;
			return EXIT_FAILURE;
		}
	}
	for (int i = 0; i<NUM_ELE; i++)
		vP[i]->n = rand();
	cout << "ordinamento puntatori" << endl;
	//start = time (0);  //faccio partire il tempo
	gettimeofday(&t1, NULL);
	for (int i=0; i<NUM_ELE-1; i++)	{
		for(int j=i+1; j<NUM_ELE; j++){
			if (vP[j]->n <= vP[i]->n){
					t_elemento *temp = vP[i];
					vP[i] = vP[j];
					vP[j] = temp;
			}
		}
	}
	//stop = time(0);
	gettimeofday(&t2, NULL);
	// tv_Usec = microsecondi per questo motivo dividiamo per 1000.0 
	double millisec = (t2.tv_usec - t1.tv_usec) / 1000.0;
	//cout << "Tempo con i puntatori: " << difftime(stop, start) << endl;
	cout << "delta time (millisec): " << millisec << endl;
	for (int i = 0; i<NUM_ELE; i++)
		cout << " " << vP[i]->n ;
	cout << endl;
	// dealloc memory
	for (int i = 0; i<NUM_ELE; i++){
		delete vP[i];
		vP[i] = nullptr;
	}
	return EXIT_SUCCESS;
}