[자료구조]스택, 큐, infix, postfix C언어 소스코드입니다.
- 최초 등록일
- 2013.07.29
- 최종 저작일
- 2010.06
- 12페이지/ 압축파일
- 가격 2,000원
소개글
자료구조에서 나오는 스택, 큐, infix, postfix 에 대한 C언어 소스코드입니다.
A+ 맞은 자료입니다.
목차
1. Write the postfix form of the following expressions:
2. Implement a stack (MAX_SIZE=10) for integer values. Push 1 to 10, and pop and print the numbers until the stack is empty.
3. Implement a queue (MAX_SIZE=10) for integer values. Enqueue 1 to 9, and dequeue and print the numbers until the queue is empty.
4. Implement a convertor of aninfix expression to a postfix expression. There are only single digit numbers and five operators: +, - ,*, /and ~ (minus sign operator). There can be any number of parentheses. The input expression is a string. Assume that input string have no errors. Example: "(1+2)*~3" -> "12+3~*"
5. Implement an evaluator of infix expressions. There are only single digit numbers and five operators: +, -, *, / and ~ (minus sign operator). There can be any number of parentheses. First you convert the input string into a postfix expression and then evaluate the postfix expression. Assume that input strings have no errors. Example: "(1+2)*~3" -> -9
본문내용
1. Write the postfix form of the following expressions:
(1) a * b *c postifx : abc**
(2) –a + b – c + d postfix : a–bcd+–+
(3) a * -b + c postfix : ab–*c+
(4) (a + b) * d + e / (f + a *d) +c postfix : ab+d*efad*+/c++
2. Implement a stack (MAX_SIZE=10) for integer values. Push 1 to 10, and pop and print the numbers until the stack is empty.
#include<stdio.h>
#define MAX_SIZE 10
typedef enum { false, true } bool;
typedef struct{
int top;
int item[MAX_SIZE];
} stack;
void Initstack(stack *);
bool Isempty(stack *);
bool Isfull(stack *);
void Push(stack *, int);
void Pop(stack *);
int Peak(stack *);
<중 략>
while(token[i]!=`\0`) //implement until NULL(end of string)
{
if((token[i]>=`0`)&&(token[i]<=`9`)) //token is number
{
printf("%c",token[i]);
Push(&operand,token[i]-`0`); //push operand stack
}
else if(token[i]==`(`) // if token is `(`, it always push regardless of priority
{
Push(&oper,token[i]);
}
참고 자료
없음
압축파일 내 파일목록
infix_postfix.c
queue.c
stack.c
stack_queue_infix_postfix.hwp