欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

Foundation Sorting: Single List Insertion So

系統 2079 0
    /* List Insertion Sorting.

 * Implementation history:.

 * 2013-09-15, Mars Fu, first version.

 */



#include "stdafx.h"



#include "list_insertion.h"



int 

init_list(struct s_clist *hd, int max_cnt, struct s_nodes *nodes)

{

	if (hd == NULL) return 0;

	if (max_cnt < 0) return 0;



	hd->node = NULL;



	nodes->cur = hd;

	nodes->hd = hd;

	memset(nodes->cur, 0, sizeof(struct s_clist));

	nodes->nodes_cnt = 0;

	nodes->max_nodes_cnt = max_cnt;



	debug("nodes->max_nodes_cnt %d \r\n", nodes->max_nodes_cnt);



	return 1;

}



int 

insert_list_sort(struct s_node *node, struct s_nodes *nodes, cmp_func cmp)

{

	struct s_clist *tmp;

	struct s_clist *next;



	if (node == NULL) return 0;

    if (nodes->cur == NULL) return 0;



	next = (struct s_clist *)malloc(sizeof(struct s_clist));

	if (next == NULL) {

		debug("malloc list failed \r\n");

		return 0;

	}



	next->node = node;



	tmp = nodes->hd->pre;



	if (tmp == NULL) {

		tmp = nodes->hd;

	   	tmp->next = next;

		next->pre = tmp;

		next->next = nodes->hd;

		nodes->hd->pre = next;

	}

	else {



		while (tmp != NULL) {

			if (tmp->node == NULL) break;

			if (cmp(tmp->node->key, node->key) < 0) break;

			tmp = tmp->pre;

		}



		next->next = tmp->next;

		tmp->next->pre = next;

		tmp->next = next;

		next->pre = tmp;

	}



    nodes->cur = nodes->hd->pre;

    nodes->nodes_cnt++;



	return 1;

}



int

is_list_full(struct s_nodes *nodes)

{

	return (nodes->nodes_cnt >= nodes->max_nodes_cnt);

}



int 

get_list_cnt(struct s_nodes *nodes)

{

	return nodes->nodes_cnt;

}



int 

delete_item_from_list(struct s_node *node, struct s_nodes *nodes)

{

	struct s_clist *cur;



	if(node == NULL) return 0;



	cur = nodes->hd;

	cur = cur->next;

	while(cur->node != NULL) {

		if(cur->node != node) {

			cur = cur->next;

			continue;

		}



		cur->pre->next = cur->next;

		cur->next->pre = cur->pre;



		cur->next = NULL;

		cur->pre = NULL;

		free(cur->node);

		free(cur);



		nodes->nodes_cnt--;



		return 1;

	}



	return 0;

}





#ifdef LIST_INSERTION_DEBUG



static int 

int_increasing_cmp(void* lv, void* rv)

{

	int tmp_lv, tmp_rv;

	

	tmp_lv = *(int*)lv;

	tmp_rv = *(int*)rv;



	return (tmp_lv - tmp_rv);

}



static void

debug_func(void*src, int n, int h)

{

	int i;



	debug("%d-sort:\r\n----\r\n", h);

	for (i = 0; i < n; ++i) {

		debug("%d ", *((int*)src + i));

	}

	debug("\r\n----\r\n");

}



int

main(int argc, char* argv[])

{

	int i;

	int cnt;

	const int int_items[] = { 503, 87, 512, 61, 908, 170, 897, 275, 

		                      653, 426, 154, 509, 612, 677, 765, 703

	                         };

	int ret;

	struct s_clist hd;

	struct s_nodes nodes;

	struct s_node *node;

	struct s_clist *cur;



	debug("[Testing list insertion sort].. \r\n");





	ret = init_list(&hd, 1000, &nodes);

	if (!ret) goto END;



	cnt = sizeof(int_items)/sizeof(int_items[0]);



	debug("src database:\r\n----\r\n");

	for (i = 0; i < cnt; ++i) {

		debug("%d ", int_items[i]);

	}

	debug("\r\n----\r\n");



	for (i = 0; i < cnt; ++i) {

		node = (struct s_node*)malloc(sizeof(struct s_node));

		if (node == NULL) goto END;



		node->key = (void*)(&int_items[i]);

		ret = insert_list_sort(node, &nodes, int_increasing_cmp);

		if (!ret) {

			debug("failed. \r\n");

			goto END;

		}

	}



	debug("dst database:\r\n----\r\n");

	cur = nodes.hd->next;

	while(cur->node != NULL) {

		debug("%d ", *(int*)cur->node->key);

		cur = cur->next;

	}



	debug("\r\n----\r\n");



	debug("\r\n");



	debug("[Testing list insertion sort].. done. \r\n");



END:

	while(1);

	return 0;

}



#endif /* LIST_INSERTION_DEBUG */




  

?

    #ifndef __LIST_INSERTION_H__

#define __LIST_INSERTION_H__



#define LIST_INSERTION_DEBUG



typedef int(*cmp_func)(void*, void*);

typedef void (*dbg_func)(void*, int, int);



struct s_node{

	void* key;



	void *data;

};



struct s_clist{

	struct s_clist *pre;

	struct s_clist *next;

	struct s_node *node;	

};



struct s_nodes

{

	struct s_clist *hd;

	int nodes_cnt;

    int max_nodes_cnt;

	

	struct s_clist *cur;

};



int init_list(struct s_clist *hd, int max_cnt, struct s_nodes *nodes);



int insert_list_sort(struct s_node *node, struct s_nodes *nodes);



int is_list_full(struct s_nodes *nodes);



int get_list_cnt(struct s_nodes *nodes);



int delete_item_from_list(struct s_node *node, struct s_nodes *nodes);



#endif /* __LIST_INSERTION_H__ */
  

?

    #pragma once



#include <windows.h>

#ifdef _WIN32

#define msleep(x)  Sleep(x)

#endif



#include <stdio.h>

#include <tchar.h>

#include <stdlib.h>

#include <malloc.h>

#include <string.h>

#include <math.h>



#define MY_DEBUG

#ifdef MY_DEBUG

#define debug printf

#else

#define debug(x,argc, __VA_ARGS__)	;

#endif /* MY_DEBUG */



#define F_S() debug("[%s]..\r\n", __FUNCTION__)

#define F_E() debug("[%s]..done. \r\n", __FUNCTION__)




  


Foundation Sorting: Single List Insertion Sort

Enjoy :)

Mars

Sep 15th, 2013

?

Foundation Sorting: Single List Insertion Sort


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。。?/p>

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 欧美一级黄视频 | 嫩草影院在线看 | 日本黄色小视频在线观看 | 国产精品成在线观看 | 精品国产一区探花在线观看 | 欧美行性性性o00x | 99成人免费视频 | 深爱婷婷 | 欧美性野久久久久久久久 | 欧美日韩一二三区 | 亚洲一区二区久久 | 不卡国产一区二区三区四区 | 老头巨大校花体内驰骋小说文 | 成人啪啪97丁香 | 成人福利在线观看 | 天天鲁天天爽天天视频 | 九九九热视频 | 天天射夜夜骑 | 91成人午夜性a一级毛片 | 日韩国产一区 | 国产精品爱久久久久久久小说 | www.668vv.com| 日韩在线视频一区 | 久久久久久国产精品mv | 国产熟妇久久777777 | 欧美性第一页 | 丁香久久 | 欧美精品一区二 | 国产中文字幕在线观看 | 96精品专区国产在线观看高清 | 91精品国产日韩91久久久久久 | av中文字幕在线观看 | 成人综合网站 | 日本人强jizz多人高清 | 综合九九 | 加勒比婷婷色综合久久 | 久草色网 | 一级啪啪片 | 狠狠插天天干 | 亚洲国产二区 | 欧美高清成人 |