Help with list

help with list
Hi, I'm doing a program that registers a doctor's appointment and for this I am using a linked list but this fails to run giving.
Can someone please take a look at the code and tell me what could be wrong?

edit: I'm using NetBeans 7.0.1 and the program gives error when entering in if (primeiro->prox == NULL)

This is the code:
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
#ifndef AGENDARCONSULTA_H
#define    AGENDARCONSULTA_H
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;

struct agenda {
    string horaInicio;
    string horaFim;
    string dataInicio;
    string dataFim;
    struct agenda *prox;
};

typedef struct agenda horaMarcada;

//cabecalho da lista
horaMarcada *primeiro;

class AgendarConsulta {
    horaMarcada c; //celula da lista
    
public:
    AgendarConsulta(){primeiro->prox = NULL;}
    AgendarConsulta(string hrIn, string hrFim, string dtIn, string dtFim) {
        primeiro->prox = NULL;
        c.horaInicio = hrIn;
        c.horaFim = hrFim;
        c.dataInicio = dtIn;
        c.dataFim = dtFim;
    }
    bool insereConsulta(string hrIn, string hrFim, string dtIn, string dtFim) {

        agenda* proximo = NULL;
        agenda* aux = NULL;

        //insere no primeiro da lista
        if (primeiro->prox == NULL) {
            *primeiro->prox = c;
            c.horaInicio = hrIn;
            c.horaFim = hrFim;
            c.dataInicio = dtIn;
            c.dataFim = dtFim;
            return true;
        } else {
            proximo = primeiro->prox;

            //procura na lista data para insercao
            //se chegar a nulo, fim da lista
            while (proximo->dataInicio < dtIn && proximo->prox != NULL)
                proximo = proximo->prox;

            //insere no ultimo elemento da lista
            if (proximo->prox == NULL) {
                *proximo->prox = c;
                c.horaInicio = hrIn;
                c.horaFim = hrFim;
                c.dataInicio = dtIn;
                c.dataFim = dtFim;
                return true;
            } else{
                //insere no meio da lista
                aux->prox = proximo->prox;
                *proximo->prox = c;
                c.prox = aux->prox;
                return true;
            }
        }
        return false;
    }
    
     bool verificaConsulta(string hrIn, string hrFim, string dtIn, string dtFim){
         agenda* proximo = NULL;
        
         while(proximo->prox != NULL){
             if(c.dataInicio == dtIn && c.dataFim == dtFim
                     && c.horaInicio == hrIn && c.horaFim == hrFim){
                 return true;              
             }
             return false;
         }
     }
    
};
#endif    /* AGENDARCONSULTA_H */ 


in main:
1
2
3
4
5
6
7
8
int main() 
{
    AgendarConsulta AC1;
    AC1.insereConsulta("14:00","14:30","18/10/2011","18/10/2011");
    
    
    return 0;
}


tks
Last edited on
Hi, hi, I solved the problem.
tks
Topic archived. No new replies allowed.