int main(int argc , char *argv[]) { int a[] = {0,6,7,8,6,1,5,7,8,2}; int i; int len; int ret = 0; len = sizeof(a)/sizeof(int); // a表示占用的内存空间 for (i = 0; i < len;i++) { ret = find_array(a,i); //遇到了一个 返回1 没有0 if (ret == 1) { delete_array(a,i,len);//a 数组 i 位置 len 长度 len--; i--; //这里要讲清楚 这个是为了检查刚刚赋值过来的数值 与前面的数值是否有重复 } } for (i = 0;i < len;i++) { printf("%d\n",a[i]); } return 0; }
GtkPlotArray * gtk_plot_array_list_get(GtkPlotArrayList *array_list, const gchar *name) { GList *list = NULL;; list = find_array(array_list, name); if(list) return GTK_PLOT_ARRAY(list->data); return NULL; }
void gtk_plot_array_list_add(GtkPlotArrayList *array_list, GtkPlotArray *array) { GList *list = NULL; list = find_array(array_list, array->name); if(list){ g_object_unref(G_OBJECT(list->data)); list->data = array; g_object_ref(G_OBJECT(array)); } else { array_list->arrays = g_list_append(array_list->arrays, array); g_object_ref(G_OBJECT(array)); } }
void JSONConfiguration::GetArray(IN const string &name, OUT list<any> &out_list) { const Array &val_array = find_array(_rootValue.get_obj(),name); out_list.clear(); for (Array::const_iterator iter = val_array.begin(); iter != val_array.end(); iter++) { Value_type vt = iter->type(); switch (vt) { case str_type: { out_list.push_back(iter->get_str()); break; } case bool_type: { out_list.push_back(iter->get_bool()); break; } case int_type: { out_list.push_back(iter->get_int()); break; } case real_type: { out_list.push_back(iter->get_real()); break; } case obj_type: case null_type: case array_type: default: { throw new configuration_exception("not supported JSON type. (TBD)"); } } // switch } }
real calc_check(int check,const char * exp) { real opd_stack[STACK_SIZE]; int opr_stack[STACK_SIZE]; int opd_size = 0,opr_size = 0; int state = 1/*,i*/; extern VAR * find_var (const char *); if (check) { match_exp(exp); l_get_token(); if (token_type!=TT_LINE_END) { merror_msg("illegal expr"); } } pline = exp; while(1) { l_get_token();//puts(token);SHOW_STACK; // exit if (token_type==TT_LINE_END) { break; } else if (token_type==TT_ID) { VAR * v;ARRAY * a; if (state!=1 && !check) { l_put_back(); break; } v = find_var(token); if (v!=NULL) { push_opd(v->value); move2(2); continue; } a = find_array (token); if (a!=NULL) { int index; l_get_token();//skip ( index = (int)calc_check(FALSE,pline); // delete this line,calc_check call skip ( automatically //l_get_token();//skip ) push_opd(get_element(a,index)); move2(2); continue; } merror_msg("Unrecognized identifier '%s'",token); } // constant else if (token_type==TT_INT || token_type==TT_FLOAT) { push_opd((real)atof(token)); move2(2); } // operator else if (IS_OPR(token_type)) { // neg "-" judgement if (token_type==OPR_SUB && state==1) { token_type = OPR_NEG; } // if (opr_size>0 && opr_stack[opr_size-1]!=TT_LBK && priority(token_type) <= priority(opr_stack[opr_size-1])) { real result; result = calc_pop(opd_stack,opr_stack,&opd_size,&opr_size); push_opd(result); } push_opr(token_type); move2(1); } // process '(' and ')' else if (token_type==TT_LBK) { push_opr(token_type); } else if (token_type==TT_RBK) { while(opr_stack[opr_size-1] /* top */ != TT_LBK && opr_size > 0) { real result; result = calc_pop(opd_stack,opr_stack,&opd_size,&opr_size); push_opd(result); } if (opr_stack[opr_size-1] /* top */ == TT_LBK) { opr_size--; // pop '(' } else // funcition call end { break; } } // built-in function call else if (IS_RESWORD(token_type)) { int argc = token_ext,i; real result; FUNCTION func = get_func(token_type); //printf("call <%s>\n",token); // skip '(' l_get_token (); // get all arg and push them in stack for (i=0;i<argc;++i) { result = calc_check(FALSE,pline); push_opd(result); //printf("[%d] |%.4lf|\n",i,result); } // call func result = func(opd_stack + opd_size - argc); // pop args opd_size -= argc; // push result push_opd(result); //printf("call end\n"); } else { if (check) merror_illegal_token(); else { l_put_back(); break; } } } // pop up all while(opr_size > 0) { real result; result = calc_pop(opd_stack,opr_stack,&opd_size,&opr_size); push_opd(result); } if (opd_size != 1) { merror_msg("calc:unknown error!"); } return opd_stack[0]; }
int i_execute_line (SOURCE_FILE * sf,const int todo) { l_get_line(sf);pline = line; l_get_token(); if (token_type==TT_LINE_END) { return EXE_DO;// skip empty line } else if (IS_KEYWORD(token_type)) { if (token_type==KEY_END) { return EXE_END; } else if (token_type==KEY_IF) { return i_execute_if (sf,todo); } else if (token_type==KEY_WHILE) { return i_execute_while(sf,todo); } else if (token_type==KEY_REPEAT) { return i_execute_repeat(sf,todo); } if (token_type==KEY_UNTIL) { return EXE_UNTIL; } else if (token_type==KEY_FOR) { return i_execute_for(sf,todo); } else if (token_type==KEY_CASE) { return i_execute_case(sf,todo); } else if (token_type==KEY_ELSEIF) { return EXE_ELSEIF; } else if (token_type==KEY_WHEN) { return EXE_WHEN; } else if (token_type==KEY_ELSE) { return EXE_ELSE; } if (!todo) return EXE_DO; if (token_type==KEY_BREAK) { return EXE_BREAK; } else if (token_type==KEY_RETURN) { return EXE_RETURN; } else if (token_type==KEY_GOSUB) { extern int i_call_sub (SOURCE_FILE *,const char *); l_get_token(); return i_call_sub(sf,token); } else if (token_type==KEY_DIM) { ARRAY * array; long size; while(1) { l_get_token(); // new array array = (ARRAY*)calloc(sizeof(ARRAY),1); array->name = s_strdup(token); list_push(&list_array,array); // l_get_token();// skip '(' size = (long)calc_check(FALSE,pline); if (size<=0) { merror_msg("illegal array size %d!",size); } array->size = size; array->array = calloc(sizeof(real),size); { int i; for (i=0;i<size;++i) array->array[i] = 0.0; } l_get_token();// skip ')' l_get_token(); if (token_type==TT_COM) continue; else if (token_type==TT_LINE_END) break; } } else if (token_type==KEY_EXIT) { d_exit(); } } else if(token_type==TT_ID) { if (str_eq(token,"print")) { while(1) { l_get_token(); if (token_type==TT_STRING) { printf("%s",token); } else { real result; char buf[128]; l_put_back(); result = calc_check(FALSE,pline); d_ftoa(result,buf); printf(buf); } l_get_token(); if (token_type==TT_LINE_END)break; }//while }//print else if (str_eq(token,"input")) { VAR * v;char buf[64]; while(1) { l_get_token(); v = get_var(token); gets(64,buf);puts(buf); v->value = atof(buf); l_get_token(); if (token_type==TT_LINE_END)break; }//while }//input else { ARRAY * a; VAR * var; var = find_var(token); if (var!=NULL) { l_get_token(); //skip '=' var->value = calc_check(FALSE,pline); return EXE_DO; } a = find_array(token); if(a!=NULL) { int index; l_get_token();//skip ( index = (int)calc_check(FALSE,pline); // delete this line,calc_check call skip ( automatically //l_get_token();//skip ) l_get_token();// skip = assign_element(a,index,calc_check(FALSE,pline)); return EXE_DO; } var = create_var(token); l_get_token(); //skip '=' var->value = calc_check(FALSE,pline); return EXE_DO; }//assign }// TT_ID else { merror_illegal_token(); } return EXE_DO; }