Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "string.h"
- #include "string"
- #include "iostream"
- #define maxstack 50
- using namespace std;
- typedef char ItemType;
- string input = "";
- typedef struct
- {
- ItemType Item[maxstack];
- int Count;
- }Stack;
- void InitializedStack(Stack *S)
- {
- S->Count = 0;
- }
- int Empty(Stack *S){
- return(S->Count == 0);
- }
- int Full(Stack *S){
- return(S->Count == input.length());
- }
- void Push(ItemType x, Stack *S)
- {
- if (Full(S))
- printf("Stack penuh! Data tidak dapat masuk");
- else
- {
- S->Item[S->Count] = x;
- ++S->Count;
- }
- }
- char Pop(Stack *S)
- {
- if (Empty(S))
- printf("");
- //printf("Stack masih kosong");
- else
- {
- --(S->Count);
- return (S->Item[S->Count]);
- }
- }
- void main()
- {
- int i;
- Stack tumpukan;
- InitializedStack(&tumpukan);
- //for (i = 0; i < maxstack; i++){
- printf("\t\t\t-----------------------\n");
- printf("\t\t\t| PEMBALIK KATA STACK |\n");
- printf("\t\t\t-----------------------\n");
- printf("\nMasukkan kata = ");
- getline(cin, input);
- for (i = 0;i<input.length(); i++){
- Push(input[i], &tumpukan);
- for (i = input.length(); i > 0; i--){
- printf("%c", Pop(&tumpukan));
- }
- getch(); //http://nhnotes.blogspot.com
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement