Boa tarde preciso implementar em linguagem C a função de ordenação crescente da lista e não estou conseguindo. Alguém poderia me auxiliar
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
typedef struct BLOCO{
int dado;
struct BLOCO *prox;
}BLOCO;
typedef struct LISTA{
BLOCO *start;
BLOCO *end;
}LISTA;
void startLISTA(LISTA *l){
l->start = NULL;
l->end = NULL;
}
void insereLista_cabeca(int dado, LISTA *l){
BLOCO *ptr_aux = (BLOCO*)malloc(sizeof(BLOCO));
if (ptr_aux == NULL){
printf("Memory Allocation Error");
exit(-1);
}
else{
ptr_aux->dado = dado;
ptr_aux->prox = NULL;
if(l->start == NULL){
l->start = ptr_aux;
l->end = ptr_aux;
}
else{
ptr_aux->prox = l->start;
l->start = ptr_aux;
}
}
}
void insereLista_cauda(int dado, LISTA *l){
BLOCO *ptr_aux = (BLOCO*)malloc(sizeof(BLOCO));
if (ptr_aux == NULL){
printf("Memory Allocation Error");
exit(-1);
}
else{
ptr_aux->dado = dado;
ptr_aux->prox = NULL;
if(l->start == NULL){
l->start = ptr_aux;
l->end = ptr_aux;
}
else{
l->end->prox = ptr_aux;
//ptr_aux->prox = NULL;
l->end = ptr_aux;
}
}
}
int removeLista_cabeca(LISTA *l){
BLOCO *ptr_aux = l->start;
int dado;
if(ptr_aux != NULL){
l->start = ptr_aux->prox;
ptr_aux->prox = NULL;
dado = ptr_aux->dado;
free(ptr_aux);
if(l->start == NULL){
l->end = NULL;
}
return dado;
}
else{
printf("LIST is Empty \n");
}
return dado;
}
int removeLista_cauda(LISTA *l){
BLOCO *ptr_aux_ant;
BLOCO *ptr_aux = l->start;
int dado;
if(ptr_aux != NULL){
while (ptr_aux->prox != NULL){
ptr_aux_ant = ptr_aux;
ptr_aux = ptr_aux->prox;
}
l->end = ptr_aux_ant;
ptr_aux_ant->prox = NULL;
//l->start = ptr_aux->prox;
//ptr_aux->prox = NULL;
dado = ptr_aux->dado;
free(ptr_aux);
if(l->start == NULL){
l->end = NULL;
}
return dado;
}
else{
printf("LIST is Empty \n");
}
return dado;
}
int removeLista_elemento(int dado, LISTA *l){
BLOCO *ptr_aux_ant = l->start;
BLOCO *ptr_aux = l->start;
if(ptr_aux != NULL){
while (ptr_aux->prox != NULL){
if (ptr_aux->dado == dado){
if (ptr_aux_ant == ptr_aux){
removeLista_cabeca(l);
}
else{
ptr_aux_ant->prox = ptr_aux->prox;
ptr_aux->prox = NULL;
return ptr_aux->dado;
free(ptr_aux);
}
}
ptr_aux_ant = ptr_aux;
ptr_aux = ptr_aux->prox;
}
if (ptr_aux->prox == NULL){
removeLista_cauda(l);
}
//l->end = ptr;
//ptr->prox = NULL;
//l->start = ptr_aux->prox;
//ptr_aux->prox = NULL;
//dado = ptr_aux->dado;
//free(ptr_aux);
if(l->start == NULL){
l->end = NULL;
}
return dado;
}
else{
printf("LIST is Empty \n");
}
return dado;
}
void printLISTA(LISTA *l){
BLOCO *ptr_print = l->start;
if(ptr_print != NULL){
while (ptr_print != NULL){
printf("%d ", ptr_print->dado);
ptr_print = ptr_print->prox;
}
}
else{
printf("LISTA is Empty");
return;
}
printf("\n");
}
int main(){
LISTA *li = (LISTA*) malloc(sizeof(LISTA));
if (li == NULL){
printf("Memory Allocation Error");
exit(-1);
}
else{
startLISTA(li);
insereLista_cabeca(1, li);
printLISTA(li);
insereLista_cabeca(12, li);
printLISTA(li);
insereLista_cabeca(15, li);
printLISTA(li);
insereLista_cauda(20, li);
printLISTA(li);
insereLista_cauda(25, li);
printLISTA(li);
removeLista_cabeca(li);
printLISTA(li);
removeLista_cabeca(li);
printLISTA(li);
//removeLista_cauda(li);
//printLISTA(li);
//removeLista_cabeca(li);
removeLista_elemento(20, li);
printLISTA(li);
removeLista_elemento(25, li);
printLISTA(li);
}
}