Accueil > Forum > > > > Liste doublement chaînée
Liste doublement chaînée
samedi 4 août 2007 à 22:23:02 |
Liste doublement chaînée

victorcoasne
|
Bonjour, J'ai créé une liste doublement chaînée mais celle-ci contient des erreurs de mémoire.
Pouvez-vous m'indiquez lesquelles ? struct PreListView
{
char* Col1;
char* Col2;
char* Col3;
SYSTEMTIME Col4;
char* Col5;
PreListView* pPrecedent;
PreListView* pSuivant;
};
PreListView* pPreListViewDebut=NULL;
PreListView* pPreListViewFin=NULL;
inline void VideListe()
{
PreListView* pPreListViewActu = pPreListViewFin;
while (pPreListViewActu!=NULL)
{
PreListView* pPreListViewActu2 = pPreListViewActu->pPrecedent;
delete pPreListViewActu;
pPreListViewActu = pPreListViewActu2;
}
pPreListViewFin = NULL;
pPreListViewDebut = NULL;
}
inline bool AjoutListe(char* Colon1, char* Colon2, char* Colon3,
SYSTEMTIME Colon4, char* Colon5)
{
PreListView* pPreListViewActu = NULL;
if (pPreListViewDebut==NULL)
{
pPreListViewDebut = new PreListView;
if (pPreListViewDebut==NULL)
return false;
pPreListViewDebut->pPrecedent = NULL;
pPreListViewDebut->pSuivant = NULL;
pPreListViewFin = pPreListViewDebut;
pPreListViewActu = pPreListViewDebut;
}
else
{
PreListView* pPreListViewExplore = pPreListViewDebut;
while (pPreListViewExplore!=NULL)
{
if (CompareSystemTime(pPreListViewExplore->Col4, Colon4)<0)
{
pPreListViewActu = new PreListView;
if (pPreListViewActu==NULL)
return false;
pPreListViewActu->pPrecedent = pPreListViewExplore->pPrecedent;
pPreListViewExplore->pPrecedent = pPreListViewActu;
pPreListViewActu->pSuivant= pPreListViewExplore;
if (pPreListViewActu->pPrecedent != NULL)
pPreListViewActu->pPrecedent->pSuivant = pPreListViewActu;
else
pPreListViewDebut = pPreListViewActu;
pPreListViewExplore = NULL;
}
else
pPreListViewExplore = pPreListViewExplore->pSuivant;
}
if (pPreListViewActu==NULL)
{
pPreListViewFin->pSuivant = new PreListView;
if (pPreListViewFin->pSuivant==NULL)
return false;
pPreListViewActu = pPreListViewFin->pSuivant;
pPreListViewActu->pPrecedent = pPreListViewFin;
pPreListViewFin = pPreListViewActu;
}
}
pPreListViewActu->Col1 = NULL;
pPreListViewActu->Col2 = NULL;
pPreListViewActu->Col3 = NULL;
pPreListViewActu->Col4 = Colon4;
pPreListViewActu->Col5 = NULL;
pPreListViewActu->Col1 = new char[strlen(Colon1)+1];
if (pPreListViewActu->Col1==NULL)
return false;
pPreListViewActu->Col1[0]=0;
strcpy(pPreListViewActu->Col1, Colon1);
pPreListViewActu->Col2 = new char[strlen(Colon2)+1];
if (pPreListViewActu->Col2==NULL)
return false;
pPreListViewActu->Col2[0]=0;
strcpy(pPreListViewActu->Col2, Colon2);
pPreListViewActu->Col3 = new char[strlen(Colon3)+1];
if (pPreListViewActu->Col3==NULL)
return false;
pPreListViewActu->Col3[0]=0;
strcpy(pPreListViewActu->Col3, Colon3);
pPreListViewActu->Col5 = new char[strlen(Colon5)+1];
if (pPreListViewActu->Col5==NULL)
return false;
pPreListViewActu->Col5[0]=0;
strcpy(pPreListViewActu->Col5, Colon5);
return true;
}
void AfficheListe()
{
PreListView* pPreListViewActu = pPreListViewDebut;
while (pPreListViewActu != NULL)
{
cout << pPreListViewActu->Col1 << " - " << pPreListViewActu->Col2 << " - " << pPreListViewActu->Col3 << " - " << " - " << pPreListViewActu->Col5;
pPreListViewActu = pPreListViewActu->pSuivant;
}
}
Merci d'avance et bonne prog, @++ Le créateur du site http://victorlogiciels.com
|
|
dimanche 5 août 2007 à 02:26:17 |
Re : Liste doublement chaînée

caiman125
|
Salut ma tout premiere remarque est PreListView* pPreListViewDebut=NULL; PreListView* pPreListViewFin=NULL;
ses deux lignes doit etre dans une fonction
et si tu peut indique les type d'erreurs
|
|
dimanche 5 août 2007 à 11:38:38 |
Re : Liste doublement chaînée

victorcoasne
|
Bonjour, Pourquoi dans une fonction ? Si je veux ajouter plusieurs objets en executant plusieurs fois la fonction ajouté sur action de l'utilisateur autant le laisser en global. L'erreur c'est un plantage, un bug, une erreur d'exécution lié à une mauvaise gestion de la mémoire. Merci et bonne prog, @++ Le créateur du site http://victorlogiciels.com
|
|
dimanche 5 août 2007 à 12:39:22 |
Re : Liste doublement chaînée

caiman125
|
je veux dire la fonction "main" au moins 
|
|
dimanche 5 août 2007 à 13:43:08 |
Re : Liste doublement chaînée
|
dimanche 5 août 2007 à 18:46:37 |
Re : Liste doublement chaînée

juju12
|
Quand l'élément que tu ajoutes est le dernier (code : if (pPreListViewActu==NULL), vers la fin de AjouteListe), tu as oublié d'initialiser ->pSuivant à 0 donc ça fout le bordel plus tard.
J'ai testé : on dirait que ça marche.
Encore un truc : oublie pas de désalllouer la mémoire des pointeurs (->Colx) dans VideListe() sinon bonjour les fuites.
|
|
dimanche 5 août 2007 à 19:03:51 |
Re : Liste doublement chaînée

juju12
|
ben y a eu un problème de police, désolé.
|
|
dimanche 5 août 2007 à 21:46:32 |
Re : Liste doublement chaînée

victorcoasne
|
Bonjour, Je l'ai refait en class mais problème d'insertion. Plus de plantage mémoire mais tout les membres insérés ne s'affichent pas ! La messagebox erreur 4 s'affiche mais bizarement pas la 2 ! class Trieur { private: struct PreListView { char* Col1; char* Col2; char* Col3; SYSTEMTIME Col4; char* Col5; PreListView* pPrecedent; PreListView* pSuivant; }; PreListView* pPreListViewDebut; PreListView* pPreListViewFin; int NbInsert; public: Trieur(); ~Trieur(); inline void AfficheListe(); inline bool Ajouter(char* Colon1, char* Colon2, char* Colon3, SYSTEMTIME Colon4, char* Colon5); };
Trieur::Trieur() { pPreListViewDebut=NULL; pPreListViewFin=NULL; NbInsert=0; } Trieur::~Trieur() { delete pPreListViewDebut; pPreListViewDebut=NULL; pPreListViewFin=NULL; }
inline bool Trieur::Ajouter(char* Colon1, char* Colon2, char* Colon3, SYSTEMTIME Colon4, char* Colon5) { /* Préparation de l'entrée à ajouter */ PreListView* pPreListViewActu=NULL; pPreListViewActu = new PreListView; if (pPreListViewActu==NULL) return false;
pPreListViewActu->pPrecedent = NULL; pPreListViewActu->pSuivant = NULL; pPreListViewActu->Col1 = NULL; pPreListViewActu->Col2 = NULL; pPreListViewActu->Col3 = NULL; pPreListViewActu->Col4 = Colon4; pPreListViewActu->Col5 = NULL;
pPreListViewActu->Col1 = new char[strlen(Colon1)+1]; if (pPreListViewActu->Col1==NULL) return false; pPreListViewActu->Col1[0]=0; strcpy(pPreListViewActu->Col1, Colon1);
pPreListViewActu->Col2 = new char[strlen(Colon2)+1]; if (pPreListViewActu->Col2==NULL) return false; pPreListViewActu->Col2[0]=0; strcpy(pPreListViewActu->Col2, Colon2);
pPreListViewActu->Col3 = new char[strlen(Colon3)+1]; if (pPreListViewActu->Col3==NULL) return false; pPreListViewActu->Col3[0]=0; strcpy(pPreListViewActu->Col3, Colon3);
pPreListViewActu->Col5 = new char[strlen(Colon5)+1]; if (pPreListViewActu->Col5==NULL) return false; pPreListViewActu->Col5[0]=0; strcpy(pPreListViewActu->Col5, Colon5); /* Ajout de l'entrée */ if (pPreListViewDebut==NULL) { pPreListViewDebut = pPreListViewActu; pPreListViewFin = pPreListViewActu; } else { PreListView* pPreListViewExplore=pPreListViewDebut; for (int i=0;pPreListViewExplore!=NULL&&i<NbInsert;i++) { if (CompareSystemTime(pPreListViewExplore->Col4, Colon4)<0) { pPreListViewActu->pPrecedent = pPreListViewExplore->pPrecedent; pPreListViewActu->pSuivant = pPreListViewExplore; if (pPreListViewExplore->pPrecedent != NULL) pPreListViewExplore->pPrecedent->pSuivant = pPreListViewActu; else pPreListViewDebut = pPreListViewActu; pPreListViewExplore->pPrecedent = pPreListViewActu; NbInsert++; return true; } pPreListViewExplore = pPreListViewExplore->pSuivant; if (pPreListViewExplore!=NULL&&i+1>=NbInsert) { MessageBox(0, "Erreur grave de gestion de la mémoire !", "Erreur Interne !", 16); return false; } else if (pPreListViewExplore==NULL&&i+1!=NbInsert) { MessageBox(0, "Erreur grave de gestion de la mémoire (3) !", "Erreur Interne !", 16); return false; } } pPreListViewFin->pSuivant = pPreListViewActu; pPreListViewFin = pPreListViewActu; } NbInsert++; return true; }
inline void Trieur::AfficheListe() { PreListView* pPreListViewExplore=pPreListViewDebut; for (int i=0;pPreListViewExplore!=NULL&&i<NbInsert;i++) { cout << pPreListViewExplore->Col1 << pPreListViewExplore->Col2 << pPreListViewExplore->Col3 << pPreListViewExplore->Col5); pPreListViewExplore = pPreListViewExplore->pSuivant; if (pPreListViewExplore!=NULL&&i+1>=NbInsert) { MessageBox(0, "Erreur grave de gestion de la mémoire (2) !", "Erreur Interne !", 16); return; } else if (pPreListViewExplore==NULL&&i+1!=NbInsert) { MessageBox(0, "Erreur grave de gestion de la mémoire (4) !", "Erreur Interne !", 16); return; } } }
Si je met en commentaire : pPreListViewActu->pPrecedent = pPreListViewExplore->pPrecedent; pPreListViewActu->pSuivant = pPreListViewExplore; if (pPreListViewExplore->pPrecedent != NULL) pPreListViewExplore->pPrecedent->pSuivant = pPreListViewActu; else pPreListViewDebut = pPreListViewActu; pPreListViewExplore->pPrecedent = pPreListViewActu; NbInsert++; return true;là ça marche. Je précise que CompareSystemTime est une fonction perso qui compare le system time passé en 2ème par rapport en premier et renvoi 1 si supérieur, 0 si égal et -1 si inférieur Merci et bonne prog, @++ Le créateur du site http://victorlogiciels.com
|
|
lundi 6 août 2007 à 10:18:39 |
Re : Liste doublement chaînée

gagah1
|
Réponse acceptée !
Tu as oublié une instruction en rouge. En plus je comprends pas pourquoi tu utilises une fonction inline pour l'ajout d'un element
else { PreListView* pPreListViewExplore=pPreListViewDebut; for (int i=0;pPreListViewExplore!=NULL&&i<NbInsert;i++) { if (CompareSystemTime(pPreListViewExplore->Col4, Colon4)<0) { pPreListViewActu->pPrecedent = pPreListViewExplore->pPrecedent; pPreListViewActu->pSuivant = pPreListViewExplore; if (pPreListViewExplore->pPrecedent != NULL) pPreListViewExplore->pPrecedent->pSuivant = pPreListViewActu; else pPreListViewDebut = pPreListViewActu; pPreListViewExplore->pPrecedent = pPreListViewActu; NbInsert++; return true; } pPreListViewExplore = pPreListViewExplore->pSuivant; if (pPreListViewExplore!=NULL&&i+1>=NbInsert) { MessageBox(0, "Erreur grave de gestion de la mémoire !", "Erreur Interne !", 16); return false; } else if (pPreListViewExplore==NULL&&i+1!=NbInsert) { MessageBox(0, "Erreur grave de gestion de la mémoire (3) !", "Erreur Interne !", 16); return false; } } pPreListViewFin->pSuivant = pPreListViewActu; pPreListViewActu->pPrecedent = pPreListViewFin; pPreListViewFin = pPreListViewActu; } NbInsert++; return true;
|
|
lundi 6 août 2007 à 11:06:27 |
Re : Liste doublement chaînée
|
Cette discussion est classée dans : char, pprecedent, pprelistviewactu, prelistview, pprelistviewdebut
Répondre à ce message
Sujets en rapport avec ce message
Probleme GTK [ par Jo ]
Salut,Quelqu'un pourrait me dire ou est l'erreur ?char * fichier; char *z;gchar *temp;temp = gtk_entry_get_text(GTK_ENTRY(Data));fd1= fopen((char *)te
débutant butant... [ par grboss ]
Avec Dev C++, des programmes bidons ne fonctionnent pas, car ils utilisent la fonction getch(); par exemple.avec turbo c++, ca passe, mais, il y a une
ecriture fichier txt turboC++ [ par idk ]
qqun connais une fonction, qui te place le cursor, (dans un fichier),CAD qui renvoie à la ligne suivante exemple char prenom="tom"char nom="bauq" Et d
int to char ! [ par nullspace ]
Voila mon problème !J'ai une résultat sous forme de variable INT, et je veux que ce résultat soit affecté à une variable de type CHAR.Genre, si j'ai 6
soustraire 2 heures [ par Olivier ]
Salut,qqn pourrait me donner une fonction qui permettrait de soustraire 2 heures ?char * SubHour(char *,char *);Remarques :02:24:12-02:24:12=24:00:000
pb avec conio je cher cherche l'erreur( j'ai merde sur le mess precedent) [ par kin ]
portpia.cpp#include"PortPiaPc.h"void main(){ PortPiaPc inst; inst(0x320,0x0f);}PortPiaPc.cpp#include "PortPiaPc.h"#include "conio.h"PortPiaPc::PortPia
manipulation desformules logiques : URGENT [ par The_Legacy ]
Bonjour, je suis en train de développer un petit programme qui permet d'évaluer des expression logiques telles que ((a et b) ou (c et (non d))).A part
Debutant : ecrire et lire un fichier txt [ par manu ]
Bonjour a tous.Je debute, aussi desole.... :)Je cherche donc a ecrire dans un fichier txt, puis a lire ce fichier ligne a ligne, faire un split / expl
convertion CString à char[ ]! [ par souaisou ]
comment convertir de cstring a une chaine de caracteres et d'un chaine de caractere a un cstring....Merci
Conversion int -> char * [ par Xentor ]
Bonjour tout le monde, et merci de lire mon message parce que je suis un vrai débutant !Je voudrais savoir comment convertir un entier en tableau de c
Livres en rapport
|
Derniers Blogs
[TOOLS] NDEPEND 3 DANS VISUAL STUDIO, WAAAAAAAOU!!![TOOLS] NDEPEND 3 DANS VISUAL STUDIO, WAAAAAAAOU!!! par JeremyJeanson
NDepend passé en version 3. Comme pour toute version majeur, la version 3 a son lots de nouveautés : performances, fonctionnalités accrues . etc . Mais dans tout cela il y a la fonctionnalité qui dénote. Le petit truc qui fait que NDepend me fait dire Waa...
Cliquez pour lire la suite de l'article par JeremyJeanson [WF4] GROSSES MéPRISES EN PERSPECTIVE SUR LE KIT DE MIGRATION WF3->WF4[WF4] GROSSES MéPRISES EN PERSPECTIVE SUR LE KIT DE MIGRATION WF3->WF4 par JeremyJeanson
Comme un certain nombre de fanatiques des flux RSS, je suis avec grand intérêt les articles de la team WCF/WF et forcément l'annonce d'hier concernant un kit de migration WF3->WF4 m'a fait chaud au c½ur ;) (pour rappel, mon post au sujet de la migratio...
Cliquez pour lire la suite de l'article par JeremyJeanson RéUNION DU CLUB MOSS PARISRéUNION DU CLUB MOSS PARIS par VANNESTE Xavier
Bonjour à tous la réunion du club moss aura lieu le 15 mars 2010 à 14 heures:
14:00 - 14:05 Paris, EROL GIRAUDY + Gaetan BOUVERET + Nicolas Georgeault intro Présentateur : Pierre Erol GIRAUDY14:05 - 14:30 Paris, Worflow - visio Services - We...
Cliquez pour lire la suite de l'article par VANNESTE Xavier [WF4] ARGUMENT, QUI ES TU?[WF4] ARGUMENT, QUI ES TU? par JeremyJeanson
Quand je parle de Workflows ou d'activités (au passage, il s'agit de la même chose dans WF4 ;) ), je fais souvent la comparaison avec une méthode classique : Une activité peut avoir un retour, comme une méthode. Une activité peut avoir des arguments d'ent...
Cliquez pour lire la suite de l'article par JeremyJeanson [FAST] FORMATIONS GRATUITES EN E-LEARNING[FAST] FORMATIONS GRATUITES EN E-LEARNING par pierre
Bonjour, Quelques formations gratuites sur FAST: Developer Configuring Search UIs Presentation 37 minutes La...
Cliquez pour lire la suite de l'article par pierre
Logiciels
Konvertor (4.00)KONVERTOR (4.00)Le logiciel est un gestionnaire multimedia affichant, jouant et convertissant plus de 2000 format... Cliquez pour télécharger Konvertor Xlite (v 3.0 build 41150)XLITE (V 3.0 BUILD 41150)c'est un logiciel qui permet de téléphoner par Internet à l'aide d'un compte SIP pratique pour le... Cliquez pour télécharger Xlite Academy System (10.9.3.0)ACADEMY SYSTEM (10.9.3.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Pacmin (1.1.0)PACMIN (1.1.0)Adaptation du célèbre jeu d'arcade. Incarnez une équipe de fantômes ou de pacmans et détruisez vo... Cliquez pour télécharger Pacmin italc (1.0.9)ITALC (1.0.9)italc permet de voir ce que font les ordinateurs de votre réseau (attention : juste pour petit ré... Cliquez pour télécharger italc
|