当前位置: 首页>>代码示例>>C++>>正文


C++ List_push函数代码示例

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


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


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