Exemple #1
0
void DFS(stack<DFS_node*> S, bool first, list<SCC*> *SCCSSEQ){
	int time = 0;
	DFS_node* u;
	SCC * scc_tmp;

	//copy of S stack, in this way we can extract element from S, and G doesn't change
	stack<DFS_node*> G = stack<DFS_node*>(S);

	// if is the second time, we sort the stack
	if(!first){
		S=sort_stack(S);
	}
	// visit every node of the stack if the color is white
	while(!S.empty()){
		u = S.top();
		S.pop();
		if( u->color == 0 ){
			scc_tmp=new SCC;
			//cout << u->argument->getName() << " ";
			DFS_visit(G,u,&time, first, scc_tmp);
			if(!first){
				SCCSSEQ->push_back(scc_tmp);
				//cout<<scc_tmp->set<<endl;
			}
		}
	}
}
Exemple #2
0
int main()
{	

	//创建一个空的栈,pS指针指向该栈
	PSTACK pS = create_stack();
	push_stack(pS,4);
	push_stack(pS,3);
	push_stack(pS,7);
	push_stack(pS,1);
	push_stack(pS,5);
	push_stack(pS,9);
	push_stack(pS,2);
	push_stack(pS,6);

	printf("Befote Sorted:\n");
	traverse_stack(pS);
	PSTACK pS1 = sort_stack(pS);
	printf("After Sorted:\n");
	traverse_stack(pS1);
	return 0;
}
int main()
{
	std::random_device device;
	std::mt19937 generator(device());

	for (size_t n = 0; n <= 50; ++n)
	{
		std::uniform_int_distribution< size_t > distribution(0,n);

		for (int i = 0; i < 1000; ++i)
		{
			std::stack< size_t > A;

			/* add elements to the stack */
			while (A.size() < n)
			{
				A.push(distribution(generator));
			}

			sort_stack(A);

			assert(A.size() == n);

			size_t a = 0;

			/* check if the stack is now sorted */
			while (A.empty() == false)
			{
				assert(A.top() >= a);
				a = A.top();
				A.pop();
			}
		}

		std::cout << "passed random tests for stacks of size " << n << std::endl;
	}

	return 0;
}
Exemple #4
0
void
roots(void)
{
	int h, i, n;
	h = tos - 2;
	roots2();
	n = tos - h;
	if (n == 0)
		stop("roots: the polynomial is not factorable, try nroots");
	if (n == 1)
		return;
	sort_stack(n);
	save();
	p1 = alloc_tensor(n);
	p1->u.tensor->ndim = 1;
	p1->u.tensor->dim[0] = n;
	for (i = 0; i < n; i++)
		p1->u.tensor->elem[i] = stack[h + i];
	tos = h;
	push(p1);
	restore();
}
Exemple #5
0
void
eval_nroots(void)
{
	volatile int h, i, k, n;

	push(cadr(p1));
	eval();

	push(caddr(p1));
	eval();
	p2 = pop();
	if (p2 == symbol(NIL))
		guess();
	else
		push(p2);

	p2 = pop();
	p1 = pop();

	if (!ispoly(p1, p2))
		stop("nroots: polynomial?");

	// mark the stack

	h = tos;

	// get the coefficients

	push(p1);
	push(p2);
	n = coeff();
	if (n > YMAX)
		stop("nroots: degree?");

	// convert the coefficients to real and imaginary doubles

	for (i = 0; i < n; i++) {
		push(stack[h + i]);
		real();
		yyfloat();
		eval();
		p1 = pop();
		push(stack[h + i]);
		imag();
		yyfloat();
		eval();
		p2 = pop();
		if (!isdouble(p1) || !isdouble(p2))
			stop("nroots: coefficients?");
		c[i].r = p1->u.d;
		c[i].i = p2->u.d;
	}

	// pop the coefficients

	tos = h;

	// n is the number of coefficients, n = deg(p) + 1

	monic(n);

	for (k = n; k > 1; k--) {
		findroot(k);
		if (fabs(a.r) < DELTA)
			a.r = 0.0;
		if (fabs(a.i) < DELTA)
			a.i = 0.0;
		push_double(a.r);
		push_double(a.i);
		push(imaginaryunit);
		multiply();
		add();
		divpoly(k);
	}

	// now make n equal to the number of roots

	n = tos - h;

	if (n > 1) {
		sort_stack(n);
		p1 = alloc_tensor(n);
		p1->u.tensor->ndim = 1;
		p1->u.tensor->dim[0] = n;
		for (i = 0; i < n; i++)
			p1->u.tensor->elem[i] = stack[h + i];
		tos = h;
		push(p1);
	}
}