Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Help

Name: Anonymous 2012-05-04 18:13

New to /prog/, do you guys help other people with their codes? if so can you help me with one that's killing me from inside out? if not, let's discuss whatever you guys do here.

Name: WE are PROG. I AM PROG! 2012-05-04 18:15

Yes, we do.

Name: Anonymous 2012-05-04 18:15

>>2
i bet u even kill /x/ now

Name: Anonymous 2012-05-04 18:19

I'm kinda curious now, what's eating you inside out?

Name: Anonymous 2012-05-04 18:21

>>2
Can you help me with this function? It adds a new node into a simple double linked list in C, feels like someone is bad but I can't pintpoint what:

insertar_elemento == "insert element" or node.
lista == list, lista_actual == current list
elemento == data to add
pos == position in the list to add the node


void insertar_elemento(lista * lista_actual, int elemento, unsigned int pos){

    int i;
    nodo *nvo_nodo;
    nvo_nodo = (nodo *) malloc (sizeof(nodo));
    nvo_nodo->dato = elemento;
    if((*lista_actual).primero == NULL && (*lista_actual).ultimo == NULL){
        nvo_nodo->sig = NULL;
        nvo_nodo->prev = NULL;
        (*lista_actual).primero = nvo_nodo;
        (*lista_actual).ultimo = nvo_nodo;
    }else{
        nvo_nodo->prev = NULL;
        nvo_nodo->sig = (*lista_actual).primero;
        for(i=0; i<=pos; i++){
            if(i != pos && i < (*lista_actual).tamanio){
                nvo_nodo->sig->prev = nvo_nodo->prev;
                if(nvo_nodo->prev != NULL) nvo_nodo->prev->sig = nvo_nodo->sig;
                nvo_nodo->prev = nvo_nodo->sig;
                if(nvo_nodo->prev->sig == NULL){
                    nvo_nodo->sig = NULL;
                    nvo_nodo->prev->sig = nvo_nodo;
                    (*lista_actual).ultimo = nvo_nodo;
                }else{
                    nvo_nodo->prev->sig->prev = nvo_nodo;
                    nvo_nodo->sig = nvo_nodo->prev->sig;
                    nvo_nodo->prev->sig = nvo_nodo;
                }
                if(i == 0)(*lista_actual).primero = nvo_nodo->prev;

            }
        }

    }
    lista_actual->tamanio++;
}

Name: Anonymous 2012-05-04 18:23

BRBRBRBRRBRBR

Name: Anonymous 2012-05-04 18:27

1. use ->
2. use ++symbol instead of symbol++
3. don't use symbol == 0
4. stick to your indent style
5. don't return void

Name: Anonymous 2012-05-04 18:28

>>6
Not BR, chilean in fact, if the names bother you I can try to translate them for you.

It's weird by the way that yo get so angry about it, since we non-english speakers have to deal with all the english in this area.

Name: Anonymous 2012-05-04 18:33

>>8
I'm coolcoolcoolcoolcoolcoolcool

Name: Anonymous 2012-05-04 18:49

I'm Mexican and I program in English.

Name: Anonymous 2012-05-04 18:49

>>7
Did that, same results, it's like anything I do inside that function doesn't get reflected in the main(), except the tamanio++

Name: Anonymous 2012-05-04 18:57

Post your code again with [code] tags, because I'm not reading that.

Name: Anonymous 2012-05-04 18:59

void insertar_elemento(lista * lista_actual, int elemento, unsigned int pos){

    int i;
    nodo *nvo_nodo;
    nvo_nodo = (nodo *) malloc (sizeof(nodo));
    nvo_nodo->dato = elemento;
    if(lista_actual->primero == NULL && lista_actual->ultimo == NULL){
        nvo_nodo->sig = NULL;
        nvo_nodo->prev = NULL;
        lista_actual->primero = nvo_nodo;
        lista_actual->ultimo = nvo_nodo;
    }else{
        nvo_nodo->prev = NULL;
        nvo_nodo->sig = lista_actual->primero;
        for(i=0; i<=pos; i++){
            if(i != pos && i < lista_actual->tamanio){
                nvo_nodo->sig->prev = nvo_nodo->prev;
                if(nvo_nodo->prev != NULL) nvo_nodo->prev->sig = nvo_nodo->sig;
                nvo_nodo->prev = nvo_nodo->sig;
                if(nvo_nodo->prev->sig == NULL){
                    nvo_nodo->sig = NULL;
                    nvo_nodo->prev->sig = nvo_nodo;
                    lista_actual->ultimo = nvo_nodo;
                }else{
                    nvo_nodo->prev->sig->prev = nvo_nodo;
                    nvo_nodo->sig = nvo_nodo->prev->sig;
                    nvo_nodo->prev->sig = nvo_nodo;
                }
                if(i == 0)lista_actual->primero = nvo_nodo->prev;

            }
           
        }

    }
    ++lista_actual->tamanio;
}

Name: bampu pantsu 2012-05-29 4:46

bampu pantsu

Don't change these.
Name: Email:
Entire Thread Thread List