示例#1
0
int main (void) {
	FILE *test;
	char name[20];
	int grade;
	Student S;
	Tree T; 
	
	Initialize(&T,copyStudent,destroyStudent,compareStudents);
	printf("Initialize()\n");
	printf("Size=%d, Height=%d, ",Size(&T),Height(&T));
	if(Balanced(&T)) printf("Balanced=YES\n\n");
	else printf("Balanced=NO\n\n");
	
	test=fopen("test.txt","r");
	while(fscanf(test,"%s %d",name,&grade)==2) {
		InitializeStudent(name,grade,&S);
		Insert(&T,&S);
		printf("Insert(%s,%d)\n",NameOfStudent(S),GradeOfStudent(S));
		printf("Size=%d, Height=%d, ",Size(&T),Height(&T));
		if(Balanced(&T)) printf("Balanced=YES\n\n");
		else printf("Balanced=NO\n\n");
		FreeStudent(&S);
	}
	fclose(test);
	
	Minimum(&T,&S);
	do {
		printf("%s\t%d%%\n",NameOfStudent(S),GradeOfStudent(S));
		FreeStudent(&S);
	}
	while(Successor(&T,&S));
	
	Destroy(&T);
	return EXIT_SUCCESS;
}
示例#2
0
static void showQueueContent (Queue *Q) {
	int i;
	Student S;
	for(i=0;i<Size(Q);i++) {
		Head(Q, &S);
		printf("\t%s %d%%\n",NameOfStudent(S),GradeOfStudent(S));
		FreeStudent(&S);
	}
	for(i = 0;i<Size(Q);i++) {
		Tail(Q, &S);
		FreeStudent(&S);
	}
}
示例#3
0
int main(void) 
{
	FILE *test;
	char s[20];
	int grade;
	
	Student S;
	Queue Q; 
	
	Initialize(&Q);
	showQueueSize(&Q);
	showQueueContent(&Q);
	
	test=fopen("test.txt","r");
    //loop checks for a command in txt file either "Insert" or "Delete"
	while(fscanf(test,"%s",s)==1) 
    {
		if(strcmp(s,"Insert")==0) 
        {
			fscanf(test,"%s %d",s,&grade);
			InitializeStudent(s,grade,&S);
			Enqueue(S,&Q); //adds student from the text file
			FreeStudent(&S);
		}
		if(strcmp(s,"Delete")==0)
			Dequeue(&Q); //deletes student from queue
		showQueueSize(&Q);
		showQueueContent(&Q);
	}
	
	fclose(test);
	Destroy(&Q);
	return EXIT_SUCCESS;
}
示例#4
0
int main(void) {
	FILE *test;
	char s[20];
	int grade;
	
	Student S;
	Queue Q; 
	
	Initialize(&Q);
	showQueueSize(&Q);
	showQueueContent(&Q);
	
	test=fopen("test.txt","r");
	while(fscanf(test,"%s",s)==1) {
		if(strcmp(s,"Enqueue")==0) {
			fscanf(test,"%s %d",s,&grade);
			InitializeStudent(s,grade,&S);
			Enqueue(S, &Q);
			FreeStudent(&S);
		}
		if(strcmp(s,"Dequeue")==0)
			Dequeue(&Q);
		showQueueSize(&Q);
		showQueueContent(&Q);
	}
	
	fclose(test);
	Destroy(&Q);
	return EXIT_SUCCESS;
}
示例#5
0
int main(void) {
	FILE *test;
	char s[20];
	int position, grade;
	
	Student S;
	List L; 
	
	Initialize(&L);
	showListSize(&L);
	showListContent(&L);
	
	test=fopen("test.txt","r");
	while(fscanf(test,"%s %d",s,&position)==2) {
		if(strcmp(s,"Insert")==0) {
			fscanf(test,"%s %d",s,&grade);
			InitializeStudent(s,grade,&S);
			Insert(S,position,&L);
			FreeStudent(&S);
		}
		if(strcmp(s,"Remove")==0)
			Remove(position,&L);
		showListSize(&L);
		showListContent(&L);
	}
	
	fclose(test);
	Destroy(&L);
	return EXIT_SUCCESS;
}
示例#6
0
static void showListContent (List *L) {
	int i;
	Student S;
	for(i=0;i<Size(L);i++) {
		Peek(i,L,&S);
		printf("\t%s %d%%\n",NameOfStudent(S),GradeOfStudent(S));
		FreeStudent(&S);
	}
}
示例#7
0
int main (int argc, char* argv[]) {
	FILE *test;
	char s[20];
	int i;
	Student S;
	Heap H; 
	
	i=strtol(argv[1],NULL,10);
	Initialize(&H,i,copyStudent,destroyStudent,compareStudents);
	
	test=fopen("test.txt","r");
	while(fscanf(test,"%s %d",s,&i)==2)
		if(!Full(&H)) {
			InitializeStudent(s,i,&S);			
			Insert(&H,&S);
			FreeStudent(&S);
		}
		else {
			Top(&H,&S);
			if(i>GradeOfStudent(S)) {
				Remove(&H);
				FreeStudent(&S);
				InitializeStudent(s,i,&S);
				Insert(&H,&S);
				FreeStudent(&S);
			}
		}
	fclose(test);
	
	while(!Empty(&H)) {
		Top(&H,&S);
		Remove(&H);
		printf("%s %d\n",NameOfStudent(S),GradeOfStudent(S));
		FreeStudent(&S);
	}

	Destroy(&H);
	return EXIT_SUCCESS;
}
示例#8
0
static void showQueueContent (Queue *L) 
{
	int i;
	Student S;
    int realHead = L->head;
    //loop transverses through queue via head
	for(i=0;i<Length(L);i++) 
    {
        //circulates array if maxsize is reached
        if (L->head == MAXLISTSIZE)  
        {
            L->head = 0;
        }
		Head(L,&S); //gets head of queue
		printf("\t%s %d%%\n",NameOfStudent(S),GradeOfStudent(S));
		FreeStudent(&S);
        L->head++;   
	}
    L->head = realHead; //fixes the head
}
示例#9
0
static void destroyItem (Item *X) {
	FreeStudent(X);
}
示例#10
0
void destroyStudent(void * S1) {
    Student * student1 = (Student *)S1;
    FreeStudent(student1);
    free(S1);
}
示例#11
0
static void destroyStudent (void *X) {
	FreeStudent(X);
	free(X); 
}