We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- C++
- Debugging
- Messages Order
- Discussions
Messages Order
Messages Order
+ 0 comments Here are the solution of Messages Order in C++ Hacker Rank Solution
+ 0 comments Here are the solution of Messages Order in C++ HackerRank Solution https://www.brokenprogrammers.com/messages-order-in-cpp-hackerrank-solution/
+ 0 comments class Message { int currId; string text; public: Message() : currId{0}, text{} {} Message(int id, const string &msgText) : currId{id}, text{msgText} {} const string& get_text() const { return text; } friend bool operator<(const Message &lhs, const Message &rhs) { return lhs.currId < rhs.currId; } }; class MessageFactory { int msgId = 0; public: MessageFactory() {} Message create_message(const string& text) { return Message{msgId++, text}; } };
+ 0 comments class Message { std::string value; long long position; public: Message() { static long long _global_order = 0; this->position = _global_order; _global_order++; } const string& get_text() { return this->value; } void set_text(const string& text) { this->value = std::string(text); } bool operator < (const Message& other){ return this->position < other.position; } }; class MessageFactory { public: MessageFactory() {} Message create_message(const string& text) { Message msg; msg.set_text(text); return msg; } };
+ 0 comments Here is problem solution - https://thecscience.com/hackerrank-messages-order-in-cpp-problem-solution.html
Load more conversations
Sort 76 Discussions, By:
Please Login in order to post a comment