⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cetc_slist_test.c

📁 linux 数据结构堆栈操作。。 。。 。。 。
💻 C
字号:
/**
 * Copyright (c) 2008, USEE 
 * All rights reserved.
 *
 * filename: cetc_slist.c
 * abstract: about single list implenments;
 *			 
 *
 * current version: 1.0
 * authors: bolidehi
 * date: 2008-8-27
 *
 * history version
 * version: 
 * authors: 
 * date: 
 */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "cetc_slist.h"
typedef struct _tagStudent tagStudent;
struct _tagStudent
{
	int		id;
	char	*name;
	int		math;
	int		chinese;
	int		english;
};

static void print_node(tagSListNode *node)
{
	tagStudent *student;
	if(node)
	{
		student = (tagStudent *)(node->data);
		printf("id=%d,name=%s\n",student->id, student->name);
	}
}

static int my_compare(void *data1, void *data2)
{
	int id = *((int *)data1);
	tagSListNode *node = (tagSListNode *)data2;
	tagStudent *stu = (tagStudent *)(node->data);
	if (id==stu->id) return 0;
	if(id > stu->id) return 1;
	return -1;
}

int main()
{
	int i;
	tagSList list;
	tagSListNode *node;
	tagStudent *student;

	cetc_init_slist(&list);
	for(i=0; i<100; i++)
	{
		student =(tagStudent *)malloc(sizeof(tagStudent));
		student->id = i;
		student->name = "xxxxxx";
		student->math = i*10;
		student->chinese =i *10;
		student->english = i *10;
		node = (tagSListNode *)malloc(sizeof(tagSListNode));
		node->data = student;
		node->next = NULL;
		cetc_add_slist_head(&list, node);
	}
	i=25;
	node = cetc_search_slist(&list, &i, my_compare);
	print_node(node);
	cetc_remove_slist_node(&list, node);

	printf("************************************\n");
	cetc_foreach_slist_do(&list, print_node);
	
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -