#include "int_set.h"
Set * int_set_new()
{
Set *result;
result-> current_elements = 0;
result-> max_elements = MIN_SIZE;
result->array =malloc(sizeof(int) * MIN_SIZE);
return result;
}
int int_set_lookup(Set*this, int item)
{
int i = 0;
int result;
int found = 0 ;
for ( int i = 0; i<this->max_elements && found ==0 ; i++){
//if (result->array[i] == item ) {
if(result->array[i]== item){ // error invalid type of argument'->'
found = 1;
}
}
if ( i>= this-> current_elements ){
found*= -1 ;
}
return found ;
}
int int_set_add(Set*this, int item){
if ( int_set_lookup(this, item) == 1){
return 0;
}
if ( this-> current_elements < this -> max_elements ){
this -> array[this->current_elements] = item ;
this->current_elements++ ;
return 1 ;
}else{
int i;
int new_array[i];
int [] new_array = malloc(sizeof(int)* 1.5*this->current_elements); // error
for ( i=0; i<this->max_elements ; i++){
new_array[i] = this->array[i];
}
this-> max_elements = 1.5*this->current_elements;
new_array[this->current_elements] = item;
this-> current_elements ++;
free ((void *)this->array);
this->array = new_array ;
return 1;
}
}
int int_set_remove(Set * this, int item){
if ( int_set_lookup(this, item) == 0){
return 0;
}
int i = 0;
int array[i];
for( i ; i< this-> current_elements && this->array != item; i++);
for( i; i< this-> current_elements-1; i++){
array[i] = array [i+1];
}
this-> current_elements-- ;
int freeSlots= this->max_elements-this->current_elements;
int maxFree= 32> this->current_elements? 16 : this->current_elements/2 ;
if( freeSlots > maxFree ){
int new_array[i];
//int [] new_array = malloc(sizeof(int)* 1.5*this->current_elements);
int [] new_array = malloc(sizeof(int)* 1.5*this->current_elements); // error
for ( i=0; i<this->current_elements ; i++){
new_array[i] = this->array[i];
}
this-> max_elements = 1.5*this->current_elements;
free ((void *)this->array);
this->array = new_array ;
}
return 1;
}
//error
带有的2 行
'[' 标记错误之前的预期标识符或 '('
如何解决上述错误?
有问题的线路是
if(result->array[i]== item){ // error invalid type of argument'->'
和
int [] new_array = malloc(sizeof(int)* 1.5*this->current_elements); // error
请帮忙!