3
This commit is contained in:
parent
15fda00eee
commit
abfe2cd136
41
a_station.c
41
a_station.c
@ -15,9 +15,9 @@ void destroy_station(struct station* station){
|
||||
struct car* start = station->tracks[i];
|
||||
struct car* this = start;
|
||||
while(this != NULL){
|
||||
next = this->next;
|
||||
free(this);
|
||||
this=next;
|
||||
this = start->next;
|
||||
free(start);
|
||||
start=this;
|
||||
}
|
||||
free(station->tracks[i]);
|
||||
}
|
||||
@ -27,8 +27,10 @@ void destroy_station(struct station* station){
|
||||
int select_track(struct station* station, const char* target){
|
||||
int c;
|
||||
int hash = station->capacity;
|
||||
char* str = target;
|
||||
while (c = *str++){
|
||||
char str[36];
|
||||
char *pstr = str;
|
||||
strcpy(str,target);
|
||||
while ((c = *pstr++)){
|
||||
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
|
||||
|
||||
return hash;
|
||||
@ -41,10 +43,13 @@ void add_target_capacity(struct station* station,const char* target, int capacit
|
||||
int track = select_track(station,target);
|
||||
struct car* start = station->tracks[track];
|
||||
if(start == NULL){
|
||||
start->value = target;
|
||||
|
||||
strcpy(start->value,target);
|
||||
start->capacity = capacity;
|
||||
start->next = NULL;
|
||||
|
||||
|
||||
|
||||
}else{
|
||||
while(start->next != NULL){
|
||||
if(strcmp(start->value,target)==0){
|
||||
@ -53,7 +58,7 @@ void add_target_capacity(struct station* station,const char* target, int capacit
|
||||
start = start->next;
|
||||
if(start->next == NULL){
|
||||
struct car* this =(struct car*)malloc(sizeof(struct car));
|
||||
this->value = target;
|
||||
strcpy(this->value,target);
|
||||
this->capacity = capacity;
|
||||
this->next = NULL;
|
||||
start->next = this;
|
||||
@ -78,11 +83,27 @@ int get_target_capacity(struct station* station,const char* target){
|
||||
}
|
||||
|
||||
int count_targets(struct station* station){
|
||||
|
||||
return 0;
|
||||
int count=0;
|
||||
for(int i = 0;i < station->capacity;i++){
|
||||
struct car* start = station->tracks[i];
|
||||
while(start->next != NULL){
|
||||
count++;
|
||||
start = start->next;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
int count_capacity(struct station* station){
|
||||
return 0;
|
||||
int count=0;
|
||||
for(int i = 0;i< station->capacity;i++){
|
||||
struct car* start = station->tracks[i];
|
||||
while(start->next != NULL){
|
||||
count =+ start->capacity;
|
||||
start = start->next;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user