doubly linked list help!
Feb 15, 2015 at 10:38pm UTC
HI,I doing the program for my college and I don't Know why show "segmentation fault , please if you could help me I would greatly appreciate it .
this action insert of this way: "if I put this a 1 , b 2, and c 3 " . print c b a , because this list insert of way "dipolo" insert on both side of the list, but, the first insertion is in the left and second insertion now is the right and later repeat the process.
my class node , my action insert, and my int main()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
class nodito {
public :
int info;
string nnombre;
nodito *prev;
nodito *prox;
nodito (){}
nodito ( int informacion , string nomb )
{
info = informacion;
nnombre =nomb;
prev = NULL;
prox = NULL;
}
~nodito () {}
};
class list2
{
public :
nodito *prim;
nodito *ulti;
int hhh,acum;
list2 (){
hhh = -1;
acum=0;
prim =NULL;
ulti= NULL;
}
void insert2 ( int hhh, string nombre_tar , int acum){
int residuo = acum % 2;
nodito *n_new;
n_new= new nodito (hhh, nombre_tar);
n_new -> prox = NULL;
n_new -> prev = NULL;
if (( prim ==NULL) and (ulti =NULL)){
prim = ulti= n_new;
}else {
if (residuo == 0) {
n_new -> prox = ulti;
n_new -> prev = ulti -> prev;
ulti -> prev = n_new;
n_new = prim;
}else {
n_new ->prox =ulti ->prox;
n_new -> prev = ulti;
ulti -> prox= n_new;
n_new =ulti;
}
}
}
void imprimir2 () {
nodito *ayuda ;
ayuda = new nodito ();
ayuda= prim ;
if (prim ==NULL)
{
cout<< "vacia" <<endl;
}
while (ayuda!=NULL){
cout<<ayuda->nnombre<<endl;
ayuda=ayuda->prox;
}
}
};
int main ()
{
list2 m; // lista del hogar
int hor, acumulador;
string nnnn=" " ;
acumulador = 0;
while ( nnnn != "*" ){
cin>> nnnn;
if ( nnnn == "*" ){
m.imprimir2();}
else {
cin>> hor;
acumulador= acumulador + 1;
m.insert2( hor, nnnn, acumulador);
}
}
Topic archived. No new replies allowed.