|
Trouver une ressource
Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !
Sujet : Liste doublement chaînée [ Divers / Divers ] (victorcoasne)
Informations & options pour cette discussion
|
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é 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
|
|