Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ FetchContent_Declare(
set(INSTALL_GTEST OFF CACHE BOOL "Disable install" FORCE)
FetchContent_MakeAvailable(googletest)

enable_testing()
# enable_testing()

# test/stack_test.cpp harus ada
add_executable(stack_test ${TEST_DIR}/stack_test.cpp)
target_link_libraries(stack_test PRIVATE stack_lib GTest::gtest_main)
#add_executable(stack_test ${TEST_DIR}/stack_test.cpp)
#target_link_libraries(stack_test PRIVATE stack_lib GTest::gtest_main)

include(GoogleTest)
gtest_discover_tests(stack_test)
108 changes: 108 additions & 0 deletions case_study/advanced/undo_redo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#include <iostream>
#include <stdexcept>
class Stack{
private:
enum Mode{write = 1,read = 2,undo = 3,redo = 4,unknown = 5};
private:
int size;
int temp_size;
int capacity;
std::string* arr;
std::string* temp;
public:
Stack(){
this->temp_size = 0;
this->size = 0;
this->capacity = 1;
this->arr = new std::string[capacity];
this->temp = new std::string[capacity];
}
Stack(int capacity){
this->temp_size = 0;
this->size = 0;
this->capacity = capacity;
this->arr = new std::string[capacity];
this->temp = new std::string[capacity];
}
~Stack(){
delete[] arr;
}
public:
Mode classifyInput(const std::string& text){
if(text.find("read") != std::string::npos){
return read;
}else if(text.find("write") != std::string::npos){
return write;
}else if(text.find("undo") != std::string::npos){
return undo;
}else if(text.find("redo") != std::string::npos){
return redo;
}
return unknown;
}
public:
bool is_full()const noexcept{
if(size == capacity){
return true;
}
return false;
}
std::string get_operation(const std::string& text){
std::string ans = "";
Mode m = classifyInput(text);
if(m == read){
return "read";
}else if(m == write){
return "write";
}else if(m == undo){
return "undo";
}else if(m == redo){
return "redo";
}
return "";
}
bool is_empty()const noexcept{
if(size == 0){
return true;
}
return false;
}
std::string top(){
return arr[size];
}
private:
void Write(const std::string& text){
if(is_full()){
throw std::runtime_error("Stack telah penuh");
}
Mode m = classifyInput(top());
if(m == read){
arr[size] = text;
size++;
}else{
std::string operasi = get_operation(text);
if(!operasi.empty()){
std::cout << "Tidak dapat melakukan operasi" << operasi << std::endl;
}else{
std::cout << "Keyword tidak ditemukan" << std::endl;
}
}
}
void pop(){
Mode m = classifyInput(top());
if(m == undo){
temp[temp_size] = top();
temp_size++;
arr[size - 1] = "";
size--;
}
}
public:
void menu(){

}
};
int main(){
std::cin.get();
return 0;
}
24 changes: 14 additions & 10 deletions case_study/use_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class Stack{
this->s = s;
this->arr = new char[capacity];
}
//destructor
~Stack(){
delete[] arr;
}
private: //method valid parantheses
bool is_open(char bracket){
if(bracket == '{'){
Expand Down Expand Up @@ -144,17 +148,17 @@ class Stack{
return {true,'\0','\0',-1};
}

void result(){
validation_result res = valid_parantheses();
std::cout << res.is_valid << std::endl;
if(res.is_valid){
std::cout << "Bracket Is Valid " << std::endl;
}else{
std::cout << "input: " << s << std::endl;
std::cout << "Error: expected '" << res.expected << "' but found '" << res.found << "', at index " << res.index_error << std::endl;
}
void result(){
validation_result res = valid_parantheses();
std::cout << res.is_valid << std::endl;
if(res.is_valid){
std::cout << "Bracket Is Valid " << std::endl;
}else{
std::cout << "input: " << s << std::endl;
std::cout << "Error: expected '" << res.expected << "' but found '" << res.found << "', at index " << res.index_error << std::endl;
}

}
}
};
int main(){
Stack* stack1 = new Stack(100,"([)]");
Expand Down
Empty file added readme.md
Empty file.
Loading