• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ List_push函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中List_push函数的典型用法代码示例。如果您正苦于以下问题:C++ List_push函数的具体用法?C++ List_push怎么用?C++ List_push使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了List_push函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: List_Node_count

List *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,代码来源:sorting.c


示例2: List_push

char *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,代码来源:list_tests.c


示例3: List_create

List *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,代码来源:list_algos.c


示例4: LIST_FOREACH

List *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,代码来源:list_algos.c


示例5: List_create

List *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,代码来源:list_algos.c


示例6: remove_mid

void 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,代码来源:list.c


示例7: List_push

char *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,代码来源:list_tests.c


示例8: str_push_pop

void 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,代码来源:list.c


示例9: List_create

char *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,代码来源:list_algos_tests.c


示例10: push_shift

void 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,代码来源:list.c


示例11: test_copy

char* 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,代码来源:list_tests.c


示例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,代码来源:LibCurlShim.c


示例13: check

inline 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,代码来源:list_algos.c


示例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,代码来源:srcfile.c


示例15: main

int
main(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,代码来源:echo-server.c


示例16: List_create

static 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,代码来源:path.c


示例17: assert

List *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,代码来源:split_access.c


示例18: main

int 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,代码来源:linkedlist_2.c


示例19: List_join

void 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,代码来源:list.c


示例20: List_create

char *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,代码来源:list_tests.c



注:本文中的List_push函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ List_size函数代码示例发布时间:2022-05-30
下一篇:
C++ List_new函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap