fabituh13 Posted July 20, 2013 at 04:27 PM Report #519467 Posted July 20, 2013 at 04:27 PM Ola pessoal...eu estou a fazer um trabalho em C, que permite o registo de passagens nas portagens. A funcionalidade que nos pedem é: Inserir um condutor Listar condutores Inserir carros Listar carros Ler dados de ficheiros Estas são as funcionalidades base. Depois uma das funcionalidades extra é: Ordenar carros por matricula, marca e modelo. Os carros estão armazenados numa lista ligada. Nós usamos um algoritmo de ordenação, mas por alguma razão está a dar erro. O código relevante à estrutura carro é o seguinte: typedef struct carro { char *Codigo; char *Matricula; char *Marca; char *Modelo; char *Ano; char *CodigoDono; }CARRO; typedef struct nocarro { CARRO *inf; struct nocarro *seg; }NOCARRO; typedef struct listacarros { NOCARRO *inicio; int nel; }LISTACARROS; Para ordenar utilizamos um algoritmo bubblesort: void OrdenarCarroMatricula(CARRO* C, int ncarros) { int j; bool houveTroca; do { houveTroca = false; for (j= 0; j< ncarros-1; j++) if (strcmp(C[j].Matricula,C[j+1].Matricula)>0) { houveTroca = true; trocacarro(&C[j], &C[j+1]); } } while (houveTroca); } Alguém poderia perceber o que há de errado no código??
HappyHippyHippo Posted July 20, 2013 at 05:09 PM Report #519469 Posted July 20, 2013 at 05:09 PM (edited) O código relevante à estrutura carro é o seguinte: typedef struct carro { // ... }CARRO; // <----------------------------------------------------- typedef struct nocarro { }NOCARRO; // <---------------------------------------------------- typedef struct listacarros { }LISTACARROS; // <----------------------------------------------------- Para ordenar utilizamos um algoritmo bubblesort: void OrdenarCarroMatricula(CARRO* C, // <----------------------------------------------- int ncarros) { // ... } não te parece que esteja algo errado ao juntar a informação assinalada ? Edited July 20, 2013 at 05:09 PM by HappyHippyHippo IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
fabituh13 Posted July 20, 2013 at 07:50 PM Author Report #519477 Posted July 20, 2013 at 07:50 PM como assim...nao tou a perceber :/
thoga31 Posted July 20, 2013 at 07:55 PM Report #519478 Posted July 20, 2013 at 07:55 PM "carro" não define uma lista ligada, e tu na função queres organizar uma lista ligada. Não será outro tipo de dados aquele que deve ser passado à função? Knowledge is free!
fabituh13 Posted July 20, 2013 at 07:59 PM Author Report #519479 Posted July 20, 2013 at 07:59 PM ah....acho que tou a perceber...deveria ser LISTACARROS entao em vez de CARRO, certo?
thoga31 Posted July 20, 2013 at 08:02 PM Report #519480 Posted July 20, 2013 at 08:02 PM Tu construíste os tipos, deverás saber para que servem e qual deles deverás usar. Pensa um pouco e tenta. 😉 Knowledge is free!
fabituh13 Posted July 20, 2013 at 08:04 PM Author Report #519481 Posted July 20, 2013 at 08:04 PM Obrigado 😄
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now