Beispiel #1
0
rt_public main(void)
{
    /* Tests for the local variable stack */

    int i;
    char *a1, *a2;

    printf("> Starting tests for local variable stack.\n");

    /* Check the stack */
    printf(">> Checking the stack management routines.\n");
    printf(">>> Pushing one item.\n");
    epush(&loc_stack, (char *) 0);
    stack_stats();
    printf(">>> Poping the stack.\n");
    epop(&loc_stack, 1);
    stack_stats();

    /* With 10000 items */
    printf(">>> Pushing 20000 items.\n");
    for (i = 0; i < 20000; i++)
        evpush(1, &i);
    stack_stats();
    printf(">>> Poping one item.\n");
    epop(&loc_stack, 1);
    stack_stats();
    printf(">>> Poping 9999 items.\n");
    epop(&loc_stack, 9999);
    stack_stats();
    printf(">>> Poping 10000 items (stack should be empty).\n");
    epop(&loc_stack, 10000);
    stack_stats();

    /* Test collection of local vars */
    printf(">> Testing collection of local vars.\n");
    printf(">>> Creating object A (remembered)\n");
    a1 = emalloc(0);
    eremb(a1);
    printf(">>> Creating object B (not remembered)\n");
    a2 = emalloc(0);
    printf(">>> Pushing A and B in local stack.\n");
    evpush(2, &a1, &a2);
    stack_stats();
    collect_stats();
    printf(">>>> Address of A: 0x%lx\n", a1);
    printf(">>>> Address of B: 0x%lx\n", a2);
    printf(">>> Running a full collection.\n");
    plsc();
    stack_stats();
    collect_stats();
    printf(">>>> Address of A: 0x%lx (changed)\n", a1);
    printf(">>>> Address of B: 0x%lx (changed)\n", a2);
    printf(">>> Running a full collection again.\n");
    plsc();
    stack_stats();
    collect_stats();
    printf(">>>> Address of A: 0x%lx (same as first one)\n", a1);
    printf(">>>> Address of B: 0x%lx (same as first one)\n", a2);

    printf("> End of tests.\n");
    exit(0);
}
Beispiel #2
0
int _tmain(int argc, _TCHAR* argv[])
{
#ifdef _DEBUG
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);//退出时检测泄漏
#endif

	nGraph G(VER);
	G.input();
	G.print();

	
	Edge* e1 = G.adjGet(0);
	int parent = 0, child = e1->other(0);

	stack<int> vst;
	stack<Edge*> est;

	mark[0] = true;
	vst.push(parent);
	est.push(e1->NextEdge());

	while (!vst.empty())
	{
		Edge* Edetect = epop(est);
		if (Edetect != nullptr)
		{
			Edge* eNext = Edetect->NextEdge();
			est.push(eNext);
		}

		while (Edetect!=nullptr)
		{
			child = Edetect->other(parent);
			if (!mark[child])
			{
				mark[child] = true;
				//TODO: preWORK on child
				cout << parent << "  " << child << endl;
				Edetect = G.adjGet(child)->NextEdge();//避开链表头结点
				parent = child;
				child = Edetect->other(parent);
				est.push(Edetect->NextEdge());
				vst.push(parent);
			}
			else
			{
				//TODO: postWORK for (parent,child)
				//cout << parent << "  " << child << endl;
				Edetect = Edetect->NextEdge();//一旦发现已标记结点,就寻找nextEdge
				est.pop();
				if (Edetect!=nullptr)
					est.push(Edetect->NextEdge());
			}

		}
		vst.pop();
		if (!vst.empty())//防止根结点处重复pop
			parent = vst.top();
		//TODO: postWORK for (parent,child)
		//cout << parent << "  " << child << endl;
	}


	system("pause");
	return 0;
}