queuetst.c

来自「常用数据结构算法代码库」· C语言 代码 · 共 63 行

C
63
字号
/* Simple program to test the queue routines */

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <dos.h>
#include "queue.h"

#define	PRINT_LIST

void randstr(char *s,int length)
{
	int	i;

	for (i = 0; i < length; i++)
		s[i] = 'a' + (char)random('z' - 'a');
	s[i] = '\0';
}

#if 0
void main(void)
{
	QUEUE		*queue;
	char		*s;
	char		line[80];
	int			i,size,length;

	printf("Size of queue to create: ");
	gets(line);
	size = atoi(line);
	printf("Maximum length of strings: ");
	gets(line);
	length = atoi(line);

	printf("\nMemory at start: %lu\n",(unsigned long)coreleft());
	printf("\nCreating queue of %d random strings of length %d ...\n\n",size,length);

	randomize();
	queue = q_init();

	for (i = 0; i < size; i++) {
		s = q_newnode(length+1);
		randstr(s,random(length));
		q_putright(queue,s);
		printf("Adding: %s\n",s);
		}

	printf("\nMemory before deleting queue: %lu\n",(unsigned long)coreleft());

	s = q_getright(queue);
	while (s) {
		printf("Got: %s\n",s);
		q_freenode(s);
		s = q_getright(queue);
		}

	q_kill(queue,q_freenode);

	printf("\nMemory after deleting queue: %lu\n",(unsigned long)coreleft());
}
#endif

⌨️ 快捷键说明

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