Esempio n. 1
0
int main()
{
	int llist1[6] = {1,2,3,4,5,6};   //数组内容
	llink head;    //指向链表开始
	
	head = createllist(llist1,6);  //创建链表
	if(!head)
	{
		printf("内存分配失败! \n");
		exit(1);
	}
	printf("原来的链表:\n");
	printllist(head);   //输出原来链表
	head = invertllist(head);   //反转链表

	printf("反转后链表:");
	printllist(head);   //输出反转后链表
	freellist(head);   //释放链表内存
	return 0;
}
Esempio n. 2
0
int main( int argc, char *argv[] )
{

	FILE *dictionary;
	char compmethod;
	char *filename;
	char *test;
	char *nextword;
	int choice;
	int i;
	int line = 0;
	int size = DEFAULT_SIZE; //hash table size
	char buffer[MAX_LINE];
	llist *miswords;
	table *dict;

	if(( choice = getopt( argc, argv, "f:" )) == NONOPT )
	{
		printf("Please pass a command arguments -f <filename>.\n");
		return 0;
	}

	do
	{
		switch ( choice )
		{
		case 'f' :
			filename = (char*)optarg;
			printf ("Reading in file %s\n",filename);
			break;
		case '?' :
			printf("Error! Please use only the -f options (refer to README).\n");
			return 0;
		}
	} while(( choice = getopt( argc, argv, "f:" )) != NONOPT );

	printf("Assignment 3.  074.216, L01.  Trevor Bekolay, 6796723\n\n");
	printf("Which compression algorithm would you like to use? (1 or 2).\n
			\t1. Division\n
			\t2. MAD (Multiply, add, divide)\n");
	printf("How large would you like the hash table?\n
			\t1. 53\n
			\t2. 119\n
			\t3. 1013\n");

	compmethod = getchar();

	if( compmethod != '1' && compmethod != '2' )
	{
		printf("Input not recognized.  Resorting to Division method.\n");
		compmethod = '1';
	}

	i = getchar();

	if( i == '2')
	{
		size = 119;
	}
	else if( i == '3')
	{
		size = 1013;
	}

	printf("Using hash table with size %d!\n",size);

	dict = createtable(size);

	printf("Loading dictionary...\n");
	dictionary = fopen(filename, "r");

	test = fgets(buffer, DICT_MAX - 1, dictionary);

	while( test != NULL )
	{

		for(i = 0; i < strlen(buffer); i++)
			buffer[i] = tolower(buffer[i]);

		printf("%s",buffer);

		addtable( dict, size, buffer, compmethod );

		test = fgets(buffer, DICT_MAX - 1, dictionary);

	}

	printf("Dictionary loaded! Searching for misspelled words...\n");

	miswords = createllist();

	test = fgets(buffer, MAX_LINE -1, stdin);

	while( test != NULL )
	{
		line++;

		nextword = strtok(buffer, " ,.-");

		while( nextword != NULL)
		{
			for(i = 0; i < strlen(nextword) - 1; i++)
				nextword[i] = tolower(nextword[i]);

			if( searchtable(dict, size, nextword, compmethod) )
			{
				addllist( miswords, buffer, line );
			}
			nextword = strtok(NULL, " ,.-");
		}

		test = fgets(buffer, MAX_LINE -1, stdin);

	}


	return 0;

}