begin process at 2012 02 08 22:42:33
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Divers

 > ORDONNER UN TABLEAU DE CHAR*, INT, DOUBLE, LONG, ETC ...

ORDONNER UN TABLEAU DE CHAR*, INT, DOUBLE, LONG, ETC ...


 Information sur la source

Note :
Aucune note
Catégorie :Divers Niveau :Initié Date de création :19/10/2003 Vu / téléchargé :6 315 / 81

Auteur : vObjects

Ecrire un message privé
Commentaire sur cette source (0)
Ajouter un commentaire et/ou une note

 Description

Cliquez pour voir la capture en taille normale
Ce petit bout de code permet de mettre en ordre croissant ou décroissant des tableaux de
signed/unsigned char*
signed/unsigned char
signed/unsigned int
signed/unsigned long
double
float
long double
signed/unsigned short
long signed/unsigned int
etc ...
etc ...
etc ...

Source

  • /*
  • **** Fichier main.cpp, exemple avec un tableau de char*
  • */
  • #include <iostream> // cout/endl
  • using namespace std;
  • #include <memory.h> // memset()/memcpy()
  • #include <stdlib.h> // system()
  • #include "vsort.h" // order()/disorder()
  • #include <windows.h> // GetTickCount()
  • int main() {
  • int i=0;
  • char** listOfItem=0;
  • DWORD dwStart=0;
  • DWORD dwEnd=0;
  • // allocations de mémoire
  • listOfItem = new char*[15]; // max de 15 éléments
  • for (i=0; i<15; i++) {
  • listOfItem[i] = new char[255]; // max de 255 caractères par élément
  • memset(listOfItem[i], 0, 255); // init à 0
  • }
  • // assignation des items
  • memcpy(listOfItem[0], "listOfItem", 10);
  • memcpy(listOfItem[1], "memset", 6);
  • memcpy(listOfItem[2], "new", 3);
  • memcpy(listOfItem[3], "char", 4);
  • memcpy(listOfItem[4], "for", 3);
  • memcpy(listOfItem[5], "listOfItem = new char*[15];", 27);
  • memcpy(listOfItem[6], "for (i=0; i<15; i++) {", 22);
  • memcpy(listOfItem[7], "listOfItem[i] = new char[255];", 30);
  • memcpy(listOfItem[8], "int i=0;", 8);
  • memcpy(listOfItem[9], "return 0;", 9);
  • memcpy(listOfItem[10], "using namespace std;", 20);
  • memcpy(listOfItem[11], "#include <memory.h>", 19);
  • memcpy(listOfItem[12], "int main() {", 12);
  • memcpy(listOfItem[13], "#include 'vstrlwrupr.h'", 23);
  • memcpy(listOfItem[14], "#include 'vsort.h'", 18);
  • // affichage d'information
  • cout << "Liste des items avant classement" << endl << endl;
  • // listing des items
  • for (i=0; i<15; i++){
  • cout << i << ") " << listOfItem[i] << endl;
  • }
  • // Fin du listing
  • cout << endl << "Fin de la liste" << endl << endl;
  • // Fait une pause
  • system("pause");
  • // Affichage d'information
  • cout << endl << "Liste des items apres classement en ordre alpha" << endl << endl;
  • dwStart = GetTickCount();
  • // Classe en ordre alpha
  • if ( order(listOfItem, 14) > 0 ) { // Si plus grand que zéro, aucune erreur
  • dwEnd = GetTickCount();
  • // Listing des items après classement
  • for (i=0; i<15; i++) {
  • cout << i << ") " << listOfItem[i] << endl;
  • }
  • // Fin du listing
  • cout << endl << "Fin de la liste" << endl << endl;
  • // Affichage du temp d'execution
  • cout << "Temp d'execution du classement: " << (long)(dwEnd-dwStart) << endl << endl;
  • }
  • else { // Plus petit que zéro, erreur
  • cout << "Erreur lors du classement" << endl << endl;
  • }
  • // Fait une pause
  • system("pause");
  • // Affichage d'information
  • cout << endl << "Liste des items apres classement en deordre alpha" << endl << endl;
  • dwStart = GetTickCount();
  • // Classe en ordre alpha
  • if ( disorder(listOfItem, 14) > 0 ) { // Si plus grand que zéro, aucune erreur
  • dwEnd = GetTickCount();
  • // Listing des items après classement
  • for (i=0; i<15; i++) {
  • cout << i << ") " << listOfItem[i] << endl;
  • }
  • // Fin du listing
  • cout << endl << "Fin de la liste" << endl << endl;
  • // Affichage du temp d'execution
  • cout << "Temp d'execution du classement: " << (long)(dwEnd-dwStart) << endl << endl;
  • }
  • else { // Plus petit que zéro, erreur
  • cout << "Erreur lors du classement" << endl << endl;
  • }
  • // Libère la mémoire
  • for (i=0; i<15; i++ ) {
  • delete [] listOfItem[i];
  • }
  • delete [] listOfItem;
  • // Fait une pause
  • //system("pause");
  • // Fin du programme
  • return 0;
  • }
/*
**** Fichier main.cpp, exemple avec un tableau de char*
*/
#include <iostream> // cout/endl
using namespace std;
#include <memory.h> // memset()/memcpy()
#include <stdlib.h> // system()
#include "vsort.h" // order()/disorder()
#include <windows.h> // GetTickCount()

int main() {

int i=0;
char** listOfItem=0;
DWORD dwStart=0;
DWORD dwEnd=0;

	// allocations de mémoire
	listOfItem = new char*[15]; // max de 15 éléments
	for (i=0; i<15; i++) {
		listOfItem[i] = new char[255]; // max de 255 caractères par élément
		memset(listOfItem[i], 0, 255); // init à 0
	}

	// assignation des items
	memcpy(listOfItem[0], "listOfItem", 10);
	memcpy(listOfItem[1], "memset", 6);
	memcpy(listOfItem[2], "new", 3);
	memcpy(listOfItem[3], "char", 4);
	memcpy(listOfItem[4], "for", 3);
	memcpy(listOfItem[5], "listOfItem = new char*[15];", 27);
	memcpy(listOfItem[6], "for (i=0; i<15; i++) {", 22);
	memcpy(listOfItem[7], "listOfItem[i] = new char[255];", 30);
	memcpy(listOfItem[8], "int i=0;", 8);
	memcpy(listOfItem[9], "return 0;", 9);
	memcpy(listOfItem[10], "using namespace std;", 20);
	memcpy(listOfItem[11], "#include <memory.h>", 19);
	memcpy(listOfItem[12], "int main() {", 12);
	memcpy(listOfItem[13], "#include 'vstrlwrupr.h'", 23);
	memcpy(listOfItem[14], "#include 'vsort.h'", 18);

	// affichage d'information
	cout << "Liste des items avant classement" << endl << endl;

	// listing des items
	for (i=0; i<15; i++){
		cout << i << ") " << listOfItem[i] << endl;
	}

	// Fin du listing
	cout << endl << "Fin de la liste" << endl << endl;

	// Fait une pause
	system("pause");
	// Affichage d'information
	cout << endl << "Liste des items apres classement en ordre alpha" << endl << endl;

	dwStart = GetTickCount();
	// Classe en ordre alpha
	if ( order(listOfItem, 14) > 0 ) { // Si plus grand que zéro, aucune erreur
		dwEnd = GetTickCount();
		// Listing des items après classement
		for (i=0; i<15; i++) {
			cout << i << ") " << listOfItem[i] << endl;
		}
		// Fin du listing
		cout << endl << "Fin de la liste" << endl << endl;
		// Affichage du temp d'execution
		cout << "Temp d'execution du classement: " << (long)(dwEnd-dwStart) << endl << endl;
	}
	else { // Plus petit que zéro, erreur
		cout << "Erreur lors du classement" << endl << endl;
	}

	// Fait une pause
	system("pause");
	// Affichage d'information
	cout << endl << "Liste des items apres classement en deordre alpha" << endl << endl;

	dwStart = GetTickCount();
	// Classe en ordre alpha
	if ( disorder(listOfItem, 14) > 0 ) { // Si plus grand que zéro, aucune erreur
		dwEnd = GetTickCount();
		// Listing des items après classement
		for (i=0; i<15; i++) {
			cout << i << ") " << listOfItem[i] << endl;
		}
		// Fin du listing
		cout << endl << "Fin de la liste" << endl << endl;
		// Affichage du temp d'execution
		cout << "Temp d'execution du classement: " << (long)(dwEnd-dwStart) << endl << endl;
	}
	else { // Plus petit que zéro, erreur
		cout << "Erreur lors du classement" << endl << endl;
	}

	// Libère la mémoire
	for (i=0; i<15; i++ ) {
		delete [] listOfItem[i];
	}
	delete [] listOfItem;

	// Fait une pause
	//system("pause");
	// Fin du programme
	return 0;

}


 Conclusion

Créé et testé avec VC++ 6 sous Windows 2000 Pro seulement.


*%*%*%*%*%*%*%
%
* vObjects
%
*%*%*%*%*%*%*%

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Sources du même auteur

Source avec Zip VHEAP, MANIPULATION DU HEAP(MÉMOIRE VIRTUEL)

 Sources de la même categorie

Source avec Zip ÉDITEUR DE RECTANGLES EN CONSOLE par seoseo
CONVERSION DE FICHIER EN FICHIER BMP par seoseo
Source avec Zip DETECTEUR EJP par idpro
Source avec Zip Source avec une capture SHOP MANAGER CONSOLE SUR WINDOWS par antho974
Source avec Zip JOUR DE NAISSANCE par fredg19

Commentaires et avis

Aucun commentaire pour le moment.

 Ajouter un commentaire




Nos sponsors


Sondage...

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,390 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales