Exemplo n.º 1
0
int 
main()
{
	int key, ch;
	H.hsize = 0;
	while (1) {
		printf("1.Insert\n2.Display Min Heap\n3.Pop out Minimum element\n4.Exit\n");
		scanf("%d", &ch);
		switch (ch) {
			case 1 :
				printf("Enter integer to be inserted \n");
				scanf("%d", &key);
				heapInsert(key);
				break;

			case 2 :
				displayHeap();
				break;	

			case 3 :
				delMin();
				break;

			case 4 :
				return (0);
		}
	}
}
Exemplo n.º 2
0
int main() {
	int i;
	srand(time(NULL));
	Heap * h = createHeap(100);
	for (i = 0; i < 100; ++i) {
		if (i > 20) {
			heapAdd(h, createHeapNode(FLT_MAX, i));
			continue;
		}
		heapAdd(h, createHeapNode(rand() % 100, i));
	}

	displayHeap(h);
	for (i = 0; i < 10; ++i) {
		HeapNode *tmp = heapExtractHead(h);

		fprintf(stdout, "\nAncien noeud : ");
		displayHeapNode(tmp);
		fprintf(stdout, "\n");
		tmp->c = rand() * i % 100 + 100;
		fprintf(stdout, "Nouveau noeud : ");
		displayHeapNode(tmp);

		heapAdd(h, tmp);

		displayHeap(h);
	}

	HeapNode * tmp = heapExtract(h, 2);
	tmp->c = rand() % 100;

	heapAdd(h, tmp);

	displayHeap(h);

	freeHeap(h);

	return 0;
}
Exemplo n.º 3
0
void displayGCState (GC_state s, FILE *stream) {
  fprintf (stream,
           "GC state\n");
  fprintf (stream, "\tcurrentThread = "FMTOBJPTR"\n", s->currentThread);
  displayThread (s, (GC_thread)(objptrToPointer (s->currentThread, s->heap.start)
                                + offsetofThread (s)), 
                 stream);
  fprintf (stream, "\tgenerational\n");
  displayGenerationalMaps (s, &s->generationalMaps, 
                           stream);
  fprintf (stream, "\theap\n");
  displayHeap (s, &s->heap, 
               stream);
  fprintf (stream,
           "\tlimit = "FMTPTR"\n"
           "\tstackBottom = "FMTPTR"\n"
           "\tstackTop = "FMTPTR"\n",
           (uintptr_t)s->limit,
           (uintptr_t)s->stackBottom,
           (uintptr_t)s->stackTop);
}
Exemplo n.º 4
0
void main() {
	int heap[MAX], curr = -1, item;
	char choice;
	printf("\n Enter");
	printf("\n i to Insert");
	printf("\n d to Display");
	do {
		printf("\n >> ");
		scanf("%c", &choice);
		switch(choice) {
			case 'i':
				printf(" Enter element to insert: ");
				scanf(" %d", &item);
				insertHeap(heap, &curr, item);
			case 'd':
				printf("\n");
				displayHeap(heap, curr);
				break;
			default:
				return;
		}
		scanf("%c", &choice);
	} while(1);
}