79 lines
1.4 KiB
C++
79 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include <iostream>
|
|
#include <string>
|
|
#include <stack>
|
|
|
|
namespace yaha {
|
|
class CQueue {
|
|
public:
|
|
CQueue() {
|
|
}
|
|
|
|
void append_tail(int value);
|
|
int delete_head();
|
|
|
|
private:
|
|
std::stack<int> _stk_tail;
|
|
std::stack<int> _stk_head;
|
|
};
|
|
|
|
class String {
|
|
public:
|
|
std::string replace_space(std::string s);
|
|
bool is_number(std::string s);
|
|
|
|
std::string reverse_left_words(std::string s, int n);
|
|
};
|
|
|
|
class ListNode {
|
|
public:
|
|
int val;
|
|
ListNode *next;
|
|
ListNode(int x) : val(x), next(NULL) {}
|
|
std::vector<int> reverse_print(ListNode *head);
|
|
void reverse_stack(ListNode *head, std::vector<int> &res);
|
|
void reverse(ListNode *head, std::vector<int> &res);
|
|
};
|
|
|
|
|
|
class Node {
|
|
public:
|
|
int val;
|
|
Node *next;
|
|
Node *random;
|
|
|
|
Node(int _val) {
|
|
val = _val;
|
|
next = NULL;
|
|
random = NULL;
|
|
}
|
|
|
|
/**
|
|
* 剑指 Offer 35. 复杂链表的复制
|
|
*
|
|
* @url https://leetcode.cn/leetbook/read/illustration-of-algorithm/9p0yy1/
|
|
* @param head
|
|
* @return
|
|
*/
|
|
Node* copy_random_list(Node* head);
|
|
};
|
|
|
|
/**
|
|
* 剑指 Offer 30. 包含 min 函数的栈
|
|
*
|
|
* @url: https://leetcode.cn/leetbook/read/illustration-of-algorithm/50bp33/
|
|
*/
|
|
class MinStack {
|
|
public:
|
|
MinStack() = default;
|
|
void push(int x);
|
|
void pop();
|
|
int top();
|
|
int min();
|
|
private:
|
|
std::stack<int> _stk;
|
|
std::stack<int> _min_stk;
|
|
};
|
|
|
|
} |