这篇教程C++ List_push函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中List_push函数的典型用法代码示例。如果您正苦于以下问题:C++ List_push函数的具体用法?C++ List_push怎么用?C++ List_push使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了List_push函数的27个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: List_Node_countList *quick_sort(List *list){ int count = List_Node_count(list); if(count==1 || count==0) { return list; } List *lesser = List_create(); List *greater = List_create(); Node *pivot = list->first; Node *current = pivot->next; Node *to_push; while(current!=NULL) { to_push = current; current = current->next; to_push->previous = NULL; to_push->next = NULL; if(to_push->data<pivot->data) { List_push(lesser, to_push); } else { List_push(greater, to_push); } } pivot->next = NULL; pivot->previous = NULL; return concatenate(quick_sort(lesser), pivot, quick_sort(greater));}
开发者ID:akshar-raaj,项目名称:LCTHW,代码行数:31,
示例2: List_pushchar *test_push_pop(){ List_push(list, test1); mu_assert(List_last(list) == test1, "Wrong last value"); List_push(list, test2); mu_assert(List_last(list) == test2, "Wrong last value"); List_push(list, test3); mu_assert(List_last(list) == test3, "Wrong last value"); mu_assert(List_count(list) == 3, "Wrong count on push"); char *val = List_pop(list); mu_assert(val == test3, "Wrong value on pop"); val = List_pop(list); mu_assert(val == test2, "Wrong value on pop"); val = List_pop(list); mu_assert(val == test1, "Wrong value on pop"); mu_assert(List_count(list) == 0, "Wrong count after pop."); return NULL;}
开发者ID:lotabout,项目名称:learn-c-the-hard-way,代码行数:26,
示例3: List_createList *List_merge_sort(List *list, List_compare cmp){ // 未初始化的List,视为不能排序 if(list == NULL) return NULL; // 空List和只有一个节点的List视为已经排序 if(List_count(list) < 2) return list; int i = 1; ListNode *cur = list->first; List *left = List_create(); List *right= List_create(); int middle = List_count(list) / 2; // 拆成两个List,分别排序 for(i = 1; i < middle; i++) { List_push(left, cur->value); cur=cur->next; } for(i = 1; i <= List_count(list) - middle; i++) { List_push(right, cur->value); cur=cur->next; } List *sort_left = List_merge_sort(left, cmp); List *sort_right = List_merge_sort(right, cmp); if(sort_left != left) List_destroy(left); if(sort_right != right) List_destroy(right); // merge return List_merge(sort_left, sort_right, cmp);}
开发者ID:LieGroup,项目名称:LIB_lcthw,代码行数:35,
示例4: LIST_FOREACHList *List_merge_sort(List *list, List_compare cmp){ if(List_count(list)<=1){ return list; } List *left=List_create(); List *right=List_create(); int middle=List_count(list)/2; LIST_FOREACH(list, first, next, cur){ if(middle>0){ List_push(left, cur->value); } else { List_push(right, cur->value); } middle--; } List *sort_left=List_merge_sort(left, cmp); List *sort_right=List_merge_sort(right, cmp); if(sort_left !=left) List_destroy(left); if(sort_right !=right)List_destroy(right); return List_merge(sort_left, sort_right, cmp);}
开发者ID:smusings,项目名称:LearnCTheHardWay,代码行数:27,
示例5: List_createList *List_merge(List *left, List *right, List_compare cmp) { List *result = List_create(); void *val = NULL; while(List_count(left) != 0 && List_count(right) != 0) { if(cmp(List_first(left), List_first(right)) <= 0) { val = List_shift(left); List_push(result, val); } else { val = List_shift(right); List_push(result, val); } } while(List_count(left) != 0) { val = List_shift(left); List_push(result, val); } while(List_count(right) != 0) { val = List_shift(right); List_push(result, val); } return result;}
开发者ID:mateusz94,项目名称:C-Projects,代码行数:26,
示例6: remove_midvoid remove_mid(List *list) { List_push(list, 12); List_push(list, 7); List_push(list, 8); List_remove(list, List_index(list, 1)); assert(List_size(list) == 2); assert(List_first(list)->data == 12); assert(List_last(list)->data == 8);}
开发者ID:nymacro,项目名称:tentcl,代码行数:9,
示例7: List_pushchar *test_read(){ List_push(list, tv1); List_push(list, tv2); List_push(list, tv3); LIST_ITERATOR(list){ printf("%s/n", current->value); } return NULL;}
开发者ID:cgordoncarroll,项目名称:lib-data-structs,代码行数:11,
示例8: str_push_popvoid str_push_pop(List *list) { SET_TYPE(list, string); List_push(list, "hello world"); List_push(list, "bad boy"); assert(strcmp(List_index(list, 0)->data, "hello world") == 0); assert(strcmp(List_index(list, 1)->data, "bad boy") == 0); assert(strcmp(List_first(list)->data, "hello world") == 0); assert(strcmp(List_last(list)->data, "bad boy") == 0); List_pop(list); List_pop(list);}
开发者ID:nymacro,项目名称:tentcl,代码行数:11,
示例9: List_createchar *test(){ List *list = List_create(); List_push(list, 5); List_push(list, 4); List_push(list, 3); List_push(list, 2); List_push(list, 1); List_bubble_sort(list); return NULL;}
开发者ID:williamshoops96,项目名称:LearnCTheHardWay,代码行数:14,
示例10: push_shiftvoid push_shift(List *list) { List_push(list, 12); List_push(list, 7); List_push(list, 2); assert(List_index(list, 0)->data == 12); assert(List_index(list, 1)->data == 7); assert(List_first(list)->data == 12); assert(List_last(list)->data == 2); List_shift(list); assert(List_first(list)->data == 7); List_shift(list); assert(List_first(list)->data == 2); List_shift(list); assert(List_first(list) == NULL);}
开发者ID:nymacro,项目名称:tentcl,代码行数:15,
示例11: test_copychar* test_copy() { src = List_create(); dest = List_create(); List_push(src, test1); List_push(src, test2); List_push(src, test3); List_copy(dest, src); mu_assert(List_count(dest) == 3, "Wrong copy - count."); mu_assert(List_first(dest) == test1, "Wrong copy - first."); mu_assert(List_last(dest) == test3, "Wrong copy - last."); return NULL;}
开发者ID:farbodtm,项目名称:libcds,代码行数:15,
示例12: __declspec__declspec(dllexport) void* curl_shim_multi_info_read(void* pvHandle, int* nMsgs){ // cast return from GetProcAddress as a CPROC List_T lst = NULL; CPVPROC pcp = (CPVPROC)GetProcAddress(g_hModCurl, "curl_multi_info_read"); void* pvItem; int i, nLocalMsgs, j = 0; unsigned int *pnReturn = NULL; unsigned int *pnItem; *nMsgs = 0; while ((pvItem = pcp(pvHandle, &nLocalMsgs)) != NULL) lst = List_push(lst, pvItem); *nMsgs = List_length(lst); if (*nMsgs == 0) return NULL; pnReturn = (unsigned int*)malloc(3 * (*nMsgs) * sizeof(unsigned int)); for (i = 0; i < (*nMsgs); i++) { lst = List_pop(lst, (void**)&pnItem); pnReturn[j++] = pnItem[0]; pnReturn[j++] = pnItem[1]; pnReturn[j++] = pnItem[2]; } List_free(&lst); return pnReturn;}
开发者ID:NJKA001,项目名称:alexandrialibrary,代码行数:30,
示例13: checkinline List *List_merge(List *left, List *right, List_val_compare cmp) { check((left != NULL) || (right != NULL), "Tried to merge NULL."); List *merged = List_create(); void *val = NULL; while(List_count(left) > 0 || List_count(right) > 0) { if(List_count(left) > 0 && List_count(right) > 0) { if(cmp(List_first(left), List_first(right)) <= 0) { val = List_fpop(left); } else { val = List_fpop(right); } List_push(merged, val); } else if(List_count(left) > 0) { merged = List_join(merged, left); break; } else if(List_count(right) > 0) { merged = List_join(merged, right); break; } } return merged;error: return NULL;}
开发者ID:reem,项目名称:LCTHW-Lib,代码行数:29,
示例14: getline/* push lines to the line_stack, to be read next - they need to be pushed in reverse order, i.e. last pushed is next to be retrieved line may contain multiple lines separated by '/n', they are split and pushed back-to-forth so that first text is first to retrieve from getline() */void SrcFile_ungetline( SrcFile *self, char *lines ){ char *next_line, *line; size_t len; /* search next line after first '/n' */ next_line = search_next_line( lines ); /* recurse to push this line at the end */ if ( next_line ) SrcFile_ungetline( self, next_line ); /* now push this line, add a newline if missing */ len = next_line ? next_line - lines : strlen( lines ); if ( len > 0 && lines[ len - 1 ] == '/n' ) len--; /* ignore newline */ line = m_malloc( len + 2 ); /* 2 bytes extra for '/n' and '/0' */ strncpy( line, lines, len ); line[ len ] = '/n'; line[ len + 1 ] = '/0'; List_push( & self->line_stack, line );}
开发者ID:meesokim,项目名称:z88dk,代码行数:29,
示例15: mainintmain(int argc, char** argv){ if (argc != 3) print_usage("Invalid parameter count"); Server* server = NULL; if (strcmp(argv[1], "unix") == 0) server = (Server*)UnixServer_new("/tmp/echo.sock"); else if (strcmp(argv[1], "tcp") == 0) server = (Server*)TCPServer_new("0.0.0.0", 6666); else print_usage("Invalid server type"); int worker_count = atoi(argv[2]); int i; for (i = 0; i < worker_count; i++) List_push(server->workers, ConnectionWorker_new(EchoConnection_new, &connection_callbacks)); server->callbacks = &server_callbacks; Server_start(server); // blocks}
开发者ID:mikalv,项目名称:libcx,代码行数:25,
示例16: List_createstatic List *neighbours_list(World *world, Point *point, Point *destination, Hashmap *nodes){ List *neighbours = List_create(); int nx, ny; for(nx = point->x - 1; nx <= point->x + 1; nx++) { if(nx < 0 || nx >= world->width) continue; for(ny = point->y - 1; ny <= point->y + 1; ny++) { if(ny < 0 || ny >= world->height || (ny == point->y && nx == point->x) || (!World_can_enter(world, nx, ny, point->z) && !(nx == destination->x && ny == destination->y))) continue; Point *p = Point_create(nx, ny, point->z); Node *node = Node_create(p, 0, 0, NULL); Node *old_node = Hashmap_get(nodes, node); if(old_node) { Node_destroy(node); node = old_node; } else { Hashmap_set(nodes, node, node); } List_push(neighbours, node); } } return neighbours;}
开发者ID:ananthakumaran,项目名称:cave,代码行数:30,
示例17: assertList *split_access_get_all_split_sections(char *file_loc){ assert(file_loc != NULL); FILE *file; char *chr = NULL; seq_region_t *reg = NULL; file = fopen(file_loc,"r"); check(file != NULL,"Error opening split list file."); char line[250]; int i=0; List *li = List_create(); while ( fgets(line,sizeof(line),file) != NULL ){ i++; chr = malloc(sizeof(char) * 250); check_mem(chr); int start_zero_based = 0; int stop = 0; int chk = sscanf(line,"%s/t%d/t%d",chr,&start_zero_based,&stop); check(chk==3,"Error parsing split file line number %d: %s.",i,line); reg = malloc(sizeof(struct seq_region_t)); check_mem(reg); reg->beg = start_zero_based+1; reg->end = stop; reg->chr_name = chr; List_push(li,reg); } return li;error: if(reg){ if(reg->chr_name) free(reg->chr_name); free(reg); } if(chr) free(chr); return NULL;}
开发者ID:cancerit,项目名称:CaVEMan,代码行数:35,
示例18: mainint main(void){ List *list = NULL; list = List_create(); // Int Data int n1 = 1; int n2 = 2; int n3 = 3; List_push(list, &n1); List_push(list, &n2); List_push(list, &n3); List_print(list, Int_printer); List_destroy(list);}
开发者ID:TDAbboud,项目名称:collections,代码行数:17,
示例19: List_joinvoid List_join(List *left, List *right){ check(left != NULL, "Destination list is NULL"); check(right != NULL, "Source list is NULL"); LIST_FOREACH(right, first, next, cur) { List_push(left, cur->value); }
开发者ID:shackijj,项目名称:lcthw,代码行数:8,
示例20: List_createchar *test_copy(){ list = List_create(); mu_assert(List_count(list) == 0, "Wrong count before copy."); List_push(list, test1); List_push(list, test2); List_push(list, test3); List_push(list, test4); mu_assert(List_count(list) == 4, "Wrong count after push."); List *copy = List_copy(list); mu_assert(copy != list, "Copy and list have same address."); mu_assert(List_count(copy) == 4, "Copy has wrong count."); return NULL;}
开发者ID:meatballhat,项目名称:box-o-sand,代码行数:18,
示例21: serial_readint serial_read(int com, char* out) { int n = 0; if (comDataAvailable(com) > 0) { n = comRead(com, (unsigned char *)__serial_buf, __SERIAL_BUFFER_SIZE); if (n > 0) { __serial_buf[n] = '/0'; if (out) { strcpy(out, __serial_buf); } if (recvlst) { // copy incoming data to recvlst char* x = strtok(__serial_buf, "/n"); while (x != 0) { if (strstr(x, "+CIPRD") == x) { int len = strlen(x); int k = 7, l = 0, m = 0; char z1[4], z2[16]; while (l < 2) { char fc = x[k]; if (x[k] == ',' || x[k] == 0) { if (l == 0) { z1[m++] = 0; } if (l == 1) { z2[m++] = 0; } l++; m = 0; } else { if (l == 0) { z1[m++] = x[k]; } if (l == 1) { z2[m++] = x[k]; } } k++; } int id = (uint8_t)strtol(z1, 0, 10); int ln = (uint16_t)strtol(z2, 0, 10); if (ln > 0) { esp_recv_data *rd = (esp_recv_data*)malloc(sizeof(esp_recv_data)); rd->id = id; rd->len = ln; rd->data = (char*)malloc(rd->len+1); memcpy(rd->data, x+k+2, rd->len); rd->data[rd->len] = 0; List_push(recvlst, rd); } } x = strtok(0, "/n"); } } } } return n;}
开发者ID:henjuv,项目名称:ajtcl-s20c,代码行数:57,
示例22: List_createList *create_words() { int i = 0; List *words = List_create(); for(i = 0; i < NUM_VALUES; i++) { List_push(words, values[i]); } return words;}
开发者ID:reem,项目名称:LCTHW-Lib,代码行数:10,
示例23: SetTemporaryLine/*-----------------------------------------------------------------------------* Insert the given text at the current scan position*----------------------------------------------------------------------------*/void SetTemporaryLine( char *line ){ init_module();#if 0 if (*p != '/0') List_push(&input_stack, m_strdup(p)); /* save current input */#endif set_scan_buf( line, FALSE ); /* assume not at BOL */}
开发者ID:bitfixer,项目名称:bitfixer,代码行数:13,
示例24: List_createList *create_words()//creates list 'words' no bigger than NUM_VALUES{ int i = 0; List *words = List_create(); for(i = 0; i < NUM_VALUES; i++) { List_push(words, values[i]); } return words;}
开发者ID:BMJHayward,项目名称:liblcthw,代码行数:11,
示例25: Datadir_avail_mapsvoidDatadir_avail_maps (FILE *fp, char *user_mapdir, char *genomesubdir, char *fileroot) { char *mapdir; struct dirent *entry; char *filename; DIR *dp; List_T maps = NULL; char **array; int n, i; mapdir = Datadir_find_mapdir(user_mapdir,genomesubdir,fileroot); fprintf(fp,"Available maps in directory %s:/n",mapdir); if ((dp = opendir(mapdir)) == NULL) { fprintf(stderr,"Unable to open mapdir %s/n",mapdir); exit(9); } while ((entry = readdir(dp)) != NULL) { if (entry->d_name[0] != '.') { filename = (char *) CALLOC(strlen(mapdir)+strlen("/")+strlen(entry->d_name)+1, sizeof(char)); sprintf(filename,"%s/%s",mapdir,entry->d_name); if (Access_file_exists_p(filename) == true) { FREE(filename); filename = (char *) CALLOC(strlen(entry->d_name)+1,sizeof(char)); strcpy(filename,entry->d_name); maps = List_push(maps,(void *) filename); } else { FREE(filename); } } } if (closedir(dp) < 0) { fprintf(stderr,"Unable to close mapdir %s/n",mapdir); } if ((n = List_length(maps)) == 0) { fprintf(fp," (none found)/n"); } else { array = (char **) List_to_array(maps,NULL); qsort(array,n,sizeof(char *),strcmp_cmp); for (i = 0; i < n; i++) { fprintf(fp,"%s/n",array[i]); FREE(array[i]); } FREE(array); List_free(&maps); } FREE(mapdir); return;}
开发者ID:fabiocpn,项目名称:GMAP-GSNAP,代码行数:54,
示例26: List_createList *List_merge_sort(List *list, List_compare *cmp) { if (list->count == 1) { List *res = List_create(); List_push(res, list->first->value); return res; } int middle = list->count / 2; List *l= List_sublist(list, 0, middle); List *r= List_sublist(list, middle, list->count - middle); List *left = List_merge_sort(l, cmp); List *right = List_merge_sort(r, cmp); List_destroy(l); List_destroy(r); ListNode* leftNode = left->first; ListNode* rightNode = right->first; List *res = List_create(); while (leftNode != NULL || rightNode != NULL) { if (leftNode == NULL) { List_push(res, rightNode->value); rightNode = rightNode->next; } else if (rightNode == NULL) { List_push(res, leftNode->value); leftNode = leftNode->next; } else if (cmp(leftNode->value, rightNode->value) < 0) { List_push(res, leftNode->value); leftNode = leftNode->next; } else { List_push(res, rightNode->value); rightNode = rightNode->next; } } List_destroy(left); List_destroy(right); return res;}
开发者ID:aleksey-zhidkov,项目名称:learn-c,代码行数:41,
示例27: List_checkList *List_copy(List *list) { List_check(list); List *dest = NULL; if(list) { dest = List_create(); check_mem(dest); LIST_FOREACH(list, first, next, cur) { List_push(dest, cur->value); } }
开发者ID:bmoar,项目名称:c_skelly,代码行数:12,
注:本文中的List_push函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ List_size函数代码示例 C++ List_new函数代码示例 |