#include "..\CookHeader.h"

int SIZE;
Array <string> stack;
int top = -1;

bool isStackEmpty() { 
	if (top == -1)
		return true;
	else
		return false;
}

bool isStackFull() {   
	if (top >= SIZE - 1)
		return true;
	else
		return false;
}

void push(string data) {   
	if (isStackFull()) {
		return;
	}
	top++;
	stack[top] = data;
}

string pop() {   
	if (isStackEmpty()) {
		return "None";
	}
	string data = stack[top];
	stack[top] = "None";
	top--;
	return data;
}

int main() {
	SIZE = 100;
	for (int i = 0; i < SIZE; i++)
		stack.push_back("None");

	FILE* rFp = fopen("C:\\CookDataC\\indian.txt", "r");
	char str[100];

	println("----- 원본 -----");
	while (feof(rFp) == 0) {
		fgets(str, 100, rFp);
		push((string)str);
		cout << str;
	}
	fclose(rFp);

	println(endl);
	println("----- 거꾸로 처리된 결과 -----");
	while (true) {
		string line = pop();
		if (line == "None")
			break;

		Array <string> miniStack; // 각 행의 한 글자 저장할 스택
		for (int i = 0; i < len(line); i++)
			miniStack.push_back("");
		int miniTop = -1;

		for (int i = 0; i < len(line); i++) {
			string ch = line.substr(i, 1); // 한 글자씩 추출
			miniTop++;
			miniStack[miniTop] = ch;
		}
		while (true) {
			if (miniTop == -1)
				break;
			string ch = miniStack[miniTop];
			miniTop--;
			cout << ch;
		}
	}
}