Created
May 15, 2019 16:22
-
-
Save aldhinya/056b0abd43dd2b31aab3f96864c900e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//HEADER | |
const int MAX = 5; | |
int top = -1; | |
int bottom = MAX; | |
struct mahasiswa { | |
int data[MAX]; | |
}mhs; | |
bool isEmpty(){ | |
return top == -1 && bottom == MAX; | |
} | |
bool isFull () { | |
return (bottom - 1) == top; | |
} | |
void push1 (int dataBaru) { | |
if(isFull()){ | |
printf("PENUH"); | |
}else { | |
top++; | |
mhs.data[top] = dataBaru; | |
} | |
} | |
void push2 (int dataBaru) { | |
if(isFull()){ | |
printf("PENUH"); | |
}else { | |
bottom--; | |
mhs.data[bottom] = dataBaru; | |
} | |
} | |
void pop1 () { | |
top--; | |
} | |
void pop2 () { | |
bottom++; | |
} | |
void view () { | |
for (int i = 0; i <= top; i++){ | |
cout << "[" <<mhs.data[i] << "]"; | |
} | |
for (int i = bottom; i < MAX; i++){ | |
cout << "[" <<mhs.data[i] << "]"; | |
} | |
} | |
int main() | |
{ | |
bool exit = false; | |
int chooseMenu, dataB; | |
do { | |
printf("\n1. Change MAX\n2. PUSH TOP\n3. PUSH BOTTOM\n4. POP TOP\n5. POP BOTTOM\n6. VIEW\nPILIH : "); | |
cin >> chooseMenu; | |
switch (chooseMenu){ | |
case 2: | |
printf("DATA : "); cin >> dataB; | |
push1(dataB); | |
break; | |
case 3: | |
printf("DATA : "); cin >> dataB; | |
push2(dataB); | |
break; | |
case 6: | |
view(); | |
break; | |
} | |
} while (exit == false); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment