Пример #1
0
void main()
{
	while(1)
	{
		system("cls");
		printf("*** MENU ***\n");
		printf("1. INPUT\n");
		printf("2. PRINT\n");
		printf("   21. SORT PRINT(by name)\n");
		printf("3. SEARCH\n");
		printf("4. MODIFY\n");
		printf("5. DELETE\n");
		printf("6. FILE SAVE\n");
		printf("7. FILE LOAD\n");
		printf("8. EXIT\n");
		printf("CHOICE [  ]\b\b\b");

		switch(getnum())
		{
		case 1 : input(); break;
		case 2 : print(); break;
		case 3 : search(0); break;
		case 4 : modify_del(1); break;
		case 5 : modify_del(2); break;
		case 6 : file_save(); break;
		case 7 : file_load(); break;
		case 8 : end();
		case 21 : sort_print(); break;
		default : printf("Please choice again...\n");
			getch();
		}
	}
}
int sort_info(st_info *buf_head,char *data_name,const int check)	//排序 
{
	sort_link *sort_head = NULL,*r1 = NULL,*r2 = NULL,*r3 = NULL,*r4 = NULL;
	st_info *p1 = buf_head->next,*p2 = NULL;
	unsigned int i = 0,j = 0,flag_end = FALSE;
	int cmp = FALSE;
	sort_head = (sort_link *)malloc(M);
	r1 = (sort_link *)malloc(M);
	sort_head->next = r1;
	r1->next = NULL;
	r1->sort_point = p1;
	while (1)
	{
		p1 = p1->next;
		if(p1 == NULL)
			break;
		r1 = (sort_link *)malloc(N);
		r1->next = NULL;
		r1->sort_point = p1;
		r2 = sort_head;
		flag_end = FALSE;
		do{
			r3 = r2;
			r2 = r2->next;
			if(r2 == NULL)
			{
				r3->next = r1;
				break;
			}
			switch (check)
			{
			case 1:cmp = ((r1->sort_point)->height <= (r2->sort_point)->height);break;
			case 2:cmp = ((r1->sort_point)->weight <= (r2->sort_point)->weight);break;
			case 3:cmp = ((r1->sort_point)->Lung_vol <= (r2->sort_point)->Lung_vol);break;
			case 4:cmp = (strcmp((r1->sort_point)->num,(r2->sort_point)->num) <= 0);break;
			case 5:cmp = ((r1->sort_point)->height >= (r2->sort_point)->height);break;
			case 6:cmp = ((r1->sort_point)->weight >= (r2->sort_point)->weight);break;
			case 7:cmp = ((r1->sort_point)->Lung_vol >= (r2->sort_point)->Lung_vol);break;
			case 8:cmp = (strcmp((r1->sort_point)->num,(r2->sort_point)->num) >= 0);break;
			default:break;
			}
			if(cmp)
			{
				r3->next = r1;
				r1->next = r2;
				break;
			}
		}while(1);	
	}
	sort_print(sort_head,data_name);
	return 1;
}
Пример #3
0
int main (int argc, char const* argv[])
{
	char word[WORD];
	struct tnode *root = NULL;
	
	while(getword(word, WORD) != EOF) {
		if(!isalpha(word[0]) )
			continue;
		root = addNode(root, word);
	}
	//printtree(root);

	sort_print(root);
	getchar();
	return 0;
}