Exemplo n.º 1
0
void ConvToRPNExp(char exp[LEN])
{
	Stack stack;
	int expLen = strlen(exp);
	char convExp[LEN];

	int i, idx = 0;
	int flag_d = 0;
	char tok, popOp;
	
	StackInit(&stack);

	for(i=0; i<expLen; i++)
	{
		tok = exp[i];
		if (isdigit(tok)){
			convExp[idx++] = tok;
		}
		else if (tok == '.'){
			convExp[idx++] = tok;
		}
		else
		{
			convExp[idx++] = ' ';
			switch(tok)
			{
			case '(':
				SPush(&stack, tok);
				break;

			case ')':
				while(1)
				{
					popOp = SPop(&stack);
					if(popOp == '(')
						break;
					convExp[idx++] = popOp;
				}
				break;

			case '+': case '-': 
			case '*': case '/':
				while(!SIsEmpty(&stack) && 
						WhoPrecOp(SPeek(&stack), tok) >= 0)
					convExp[idx++] = SPop(&stack);

				SPush(&stack, tok);
				break;
			}
		}
	}

	while(!SIsEmpty(&stack))
		convExp[idx++] = SPop(&stack);

	convExp[idx] = '\0';

	strcpy(exp, convExp);
}
Exemplo n.º 2
0
Arquivo: 9012.c Projeto: Daehoho/study
Data SPeek(Stack* pstack) {
  if(SIsEmpty(pstack)) {
    return -1;
  }

  return pstack->stackArr[pstack->topIndex];
}
Exemplo n.º 3
0
Data SPeek(Stack * pstack)
{
	if (SIsEmpty(pstack))
	{
		printf("Stack Memory Error!");
		exit(-1);
	}

	return pstack->stackArr[pstack->topIndex];
}
Exemplo n.º 4
0
Data SPeek(Stack * pstack)
{
	if(SIsEmpty(pstack))
	{
		printf("Stack Memory Error!");
		exit(-1);
	}

	return pstack->head->data;
}
Exemplo n.º 5
0
Arquivo: 9012.c Projeto: Daehoho/study
Data SPop(Stack* pstack) {
  int rIdx;

  if(SIsEmpty(pstack)) {
    return -1;
  }

  rIdx = pstack->topIndex;
  pstack->topIndex -= 1;

  return pstack->stackArr[rIdx];
}
Exemplo n.º 6
0
void DFShowGraphVertex(ALGraph* pg, int startV)
{
	Stack stack;
	int visitV = startV;
	int nextV;

	StackInit(&stack);
	VisitVirtex(pg, visitV);
	SPush(&stack, visitV);

	
	while( LFirst(&(pg->adjList[visitV]), &nextV) == TRUE ) 
	{
		int visitFlag = FALSE;

		if(VisitVirtex(pg, nextV) == TRUE)  // if nextV is the virtex that was visited 
		{
			SPush(&stack, visitV);			// Push nextV in the stack
			visitV = nextV;
			visitFlag = TRUE;
		}
		else	// if nextV is not the virtex that was visited before   
		{
			while(LNext(&(pg->adjList[visitV]),&nextV) == TRUE)
			{
				if( VisitVirtex(pg, nextV) == TRUE) 
				{
					SPush(&stack, visitV);
					visitV = nextV;
					visitFlag = TRUE;
					break;
				}
			}

		}

		if(visitFlag == FALSE)
		{
			if(SIsEmpty(&stack) == TRUE)
				break;
			else 
				visitV = SPop(&stack);
		}

	}


	memset(pg->visitInfo, 0, sizeof(int) * pg->numOfVertex);

}
Exemplo n.º 7
0
Data SPop(Stack * pstack)
{
	int rIdx;

	if (SIsEmpty(pstack))
	{
		printf("Stack Memory Error");
		exit(-1);
	}

	rIdx = pstack->topIndex;

	pstack->topIndex -= 1;

	return pstack->stackArr[rIdx];
}
Exemplo n.º 8
0
int main()
{
	Stack stack;
	StackInit(&stack);

	SPush(&stack, 1);SPush(&stack, 2);
	SPush(&stack, 3);SPush(&stack, 4);
	SPush(&stack, 5);

	while(!SIsEmpty(&stack))
		printf("%d ", SPop(&stack));

	printf("\n");

	return 0;
}
Exemplo n.º 9
0
int main(void)
{
	// Stack의 생성 및 초기화 ///////
	Stack stack;
	StackInit(&stack);

	// 데이터 넣기 ///////
	SPush(&stack, 1);  SPush(&stack, 2);
	SPush(&stack, 3);  SPush(&stack, 4);
	SPush(&stack, 5);

	// 데이터 꺼내기 ///////
	while (!SIsEmpty(&stack))
		printf("%d ", SPop(&stack));

	return 0;
}
Exemplo n.º 10
0
Data SPop(Stack * pstack)
{
	Data rdata;
	Node * rnode;

	if(SIsEmpty(pstack))
	{
		printf("Stack Memory Error!");
		exit(-1);
	}

	rdata = pstack->head->data;
	rnode = pstack->head;

	pstack->head = pstack->head->next;
	free(rnode);

	return rdata;
}