我需要对堆栈中的元素进行随机排序

时间:2019-04-07 15:14:22

标签: c stack

我需要在PILA_centrifugar函数中对堆栈中的元素进行随机排序。我有这段代码来创建堆栈。我需要在PILA_centrifugar中实现此功能。

Pila PILA_crea() {
    Pila p;

    p = NULL;

    return p;
}

void PILA_push(Pila *p, int elemento) {
    Nodo *aux;
    aux = (Nodo*)malloc(sizeof(Nodo));
    if (aux == NULL) {
        printf("No se puede hacer push ");
    } else {
        aux->elemento = elemento;
        aux->sig = *p;
        *p = aux;
    }
}

void PILA_pop(Pila *p) {
    Nodo *aux;

    if (*p == NULL) {
        printf("\nError al hacer pop");
    } else {
        aux = *p;
        *p = (*p)->sig;
        free(aux);
    }
}

void PILA_centrifugar(Pila *p) {
    Nodo *aux;

    if (*p == NULL) {
        printf("\nError centrifugar");
    } else {
        aux = *p;
        *p = rand();
        free(aux);
    }
}

0 个答案:

没有答案