int main(int argc,char *argv[])
{
	link_t *head,t;
	int i,j;
	FILE *fp;

	V=atoi(argv[1]);
	head=malloc(V*sizeof(link_t));

	fp=fopen("adjacency_list_graph_representation.dat","r");

	for(i=0;i<V;i++){
		head[i]=allocNode(i);
		head[i]->next=NULL;
	}

	while(fscanf(fp,"%d%d",&i,&j)==2){
		t=allocNode(j);
		insertNext(head[i],t);
		t=allocNode(i);
		insertNext(head[j],t);
	}

	fclose(fp);

	print_list(head);

	return(0);
}
int main(void)
{
	link_t head[V],t;
	int i,j;
	FILE *fp;

	fp=fopen("adjacency_list_graph_representation.dat","r");

	for(i=0;i<V;i++){
		head[i]=allocNode(i);
		head[i]->next=NULL;
	}

	while(fscanf(fp,"%d%d",&i,&j)==2){
		t=allocNode(j);
		insertNext(head[i],t);
		t=allocNode(i);
		insertNext(head[j],t);
	}

	fclose(fp);

	print_list(head);

	return(0);
}
int main(void)
{
	link_t t;
	int i,j,start=0;
	FILE *fp;

	fp=fopen("adjacency_list_graph_traversal_depth_first_search_stack.dat","r");

	for(i=0;i<V;i++){
		adj[i]=allocNode(i);
		adj[i]->next=NULL;
	}

	while(fscanf(fp,"%d%d",&i,&j)==2){
		t=allocNode(j);
		insertNext(adj[i],t);
		t=allocNode(i);
		insertNext(adj[j],t);
	}

	fclose(fp);

	print_list(adj);

	putchar('\n');
	puts("traverse:");
	traverse(start,visit);
	putchar('\n');

	return(0);
}
int main(int argc,char *argv[])
{
	int N=atoi(argv[1]),i;
	link_t head,x,temp;

	initNodes(N+1);
	head=newNode(0);
	head->next=NULL;

	srand((unsigned)time(NULL));

	for(x=head,i=1;i<=N;i++){
		temp=newNode(rand()%100);
		insertNext(x,temp);
		x=temp;
	}

	print_list(head);

	move_largest_item(head);
	
	print_list(head);

	return(0);
}
void LinkedList::insertNext(node * head, node * insert)
{
	node * temp;
	if(head == NULL)
	{
		head = insert; 
	}
	else
	{
		temp = head->getRight();
		insertNext(temp, insert);
		return;
	}
}
link_t move_largest_item(const link_t head)
{
	link_t x=head,next_max,max,last_node;
	double max_value;
	
	for(max_value=Item(Next(x)),next_max=x;Next(x)!=NULL;x=Next(x))
		if(Item(Next(x)) > max_value)
			max_value=Item(Next(x)),next_max=x;
	last_node=x;

	if(Next(next_max)!=last_node){
		max=deleteNext(next_max);
		insertNext(last_node,max);
	}
	
	return(head);
}
Esempio n. 7
0
int main(int argc, char *argv[])
{
	int i, N = atoi(argv[1]), M = atoi(argv[2]);
	Node t, x;
	initNode(N);
	for (i = 2, x = newNode(1); i <= N; ++i) {
		t = newNode(1);
		insertNext(x, t);
		x = t;
	}
	while (x != Next(x)) {
		for (i = 1; i < M; i++)
			x = Next(x);
		freeNode(deleteNext(x));
	}
	printf("%d\n", Item(x));
}	
int main(int argc,char *argv[])
{
    int N=atoi(argv[1]),i;
    link_t head,x,temp,t,u;

    head=generate_node(0);
    head->next=NULL;

    srand((unsigned)time(NULL));

    for(x=head,i=1; i<=N; i++) {
        temp=generate_node(rand()%100);
        insertNext(x,temp);
        x=temp;
    }
    print_list(head);

    head=free_nodes(head);
    print_list(head);

    return(0);
}
int main(int argc,char *argv[])
{
	int i;
	link_t x,t;

	N=atoi(argv[1]),M=atoi(argv[2]);
	initNodes(N);

	for(x=newNode(1),i=2;i<=N;i++){
		t=newNode(i);
		insertNext(x,t);
		x=t;
	}

	printf("quit order:");

	t=quit(x);

	putchar('\n');
	printf("the target:%d\n",Item(t));

	return(0);
}
void freeNode(link x)
{
    insertNext(freelist, x);
}
Esempio n. 11
0
int main()
{
	clock_t start = clock();
	int const DELETE_CT = 2;
	int const PRINTSIZE = 5;
	int const HOWMANY = 20;  // How many values to read from each file.  If HOWMANY = 0, read all values.
	// SkewHeap pq1("SkewHeap PQ1");
	// LeftistHeap pq1("Leftist PQ1");
	/*PQHeap pq1("Heap PQ1", 6000);
	PQHeap pq2("Heap PQ2", 6000);
	PQHeap pq3("Heap PQ3", 6000);
	PQHeap pq4("Heap PQ4", 6000);
	PQHeap pq5("Heap PQ5", 6000);
	PQHeap pq6("Heap PQ6", 6000);*/
	SkewHeap pq1("SkewHeap PQ1");
	SkewHeap pq2("SkewHeap PQ2");
	SkewHeap pq3("SkewHeap PQ3");
	SkewHeap pq4("SkewHeap PQ4");
	SkewHeap pq5("SkewHeap PQ5");
	SkewHeap pq6("SkewHeap PQ6");
	/*Leftist pq1("LeftistHeap PQ1");
	Leftist pq2("LeftistHeap PQ2");
	Leftist pq3("LeftistHeap PQ3");
	Leftist pq4("LeftistHeap PQ4");
	Leftist pq5("LeftistHeapPQ5");
	Leftist pq6("LeftistHeapPQ6");/**/
	
	ifstream fin;
	fin.open("Prog5In.txt");
	assert(fin);

	insertNext(pq1, fin, HOWMANY);
	insertNext(pq2, fin, HOWMANY);
	insertNext(pq3, fin, HOWMANY);
	insertNext(pq4, fin, HOWMANY);
	insertNext(pq5, fin, HOWMANY);
	insertNext(pq6, fin);

	cout << pq1.toString(PRINTSIZE);
	ofstream fout;
	fout.open("prog5out.txt");
	cout << pq1.toString(PRINTSIZE);

	for (int ct = 0; ct < DELETE_CT && !pq1.isEmpty(); ct++){
		ItemType big = pq1.deleteMax();
		fout << " ** DELETED " << big.toString() << endl;
		cout << " ** DELETED " << big.toString() << endl;
		cout << pq1.toString(PRINTSIZE);
	};
	for (int ct = 0; ct < DELETE_CT && !pq2.isEmpty(); ct++) {
		ItemType big = pq2.deleteMax();
		fout << " ** DELETED " << big.toString() << endl;
		cout << " ** DELETED " << big.toString() << endl;
	};
	cout << "Before merge \n" << pq1.toString(PRINTSIZE) << endl;
	fout << "Before merge \n" << pq1.toString(PRINTSIZE) << endl;
	cout << "Before merge \n" << pq2.toString(PRINTSIZE) << endl;
	fout << "Before merge \n" << pq2.toString(PRINTSIZE) << endl;

	pq1.merge(&pq2);

	cout << "After merge \n" << pq1.toString(PRINTSIZE) << endl;
	fout << "After merge \n" << pq1.toString(PRINTSIZE) << endl;
	cout << "After merge \n" << pq2.toString(PRINTSIZE) << endl;
	fout << "After merge \n" << pq2.toString(PRINTSIZE) << endl;
	pq3.merge(&pq4);
	cout << "After merge 3 and 4 \n" << pq3.toString(PRINTSIZE) << endl;
	pq5.merge(&pq6);
	cout << "After merge 5 and 6 \n" << pq5.toString(PRINTSIZE) << endl;
	pq1.merge(&pq3);
	cout << "After merge 1 and 3\n" << pq1.toString(PRINTSIZE) << endl;
	pq1.merge(&pq5);
	cout << "After merge 1 and 5\n" << pq1.toString(PRINTSIZE) << endl;
	clock_t time = clock() - start;
	cout << "Elapsed time = " << ((float)time) / CLOCKS_PER_SEC << endl;
	fout << "Elapsed time = " << ((float)time) / CLOCKS_PER_SEC << endl;
	fout.close();
}
Esempio n. 12
0
void List::freeNode(LinkNode x)
{
  insertNext(freeList, x);
}
Esempio n. 13
0
void MemAllocList::freeNode(LinkNode x)
{
  insertNext(freeList, x);
}
Esempio n. 14
0
//将不用的节点接到freelist上
void freeNode(LinkList x)
{
    insertNext(freelist, x);
}