|
王昱祺 (12王昱祺)
|
13ms |
512 KiB |
|
202 Bytes |
2023-3-26 17:51:08 |
|
李旻轩
|
13ms |
436 KiB |
|
253 Bytes |
2023-2-11 11:33:25 |
|
56 (13883454928)
|
13ms |
512 KiB |
|
178 Bytes |
2023-4-12 18:11:18 |
|
陈红恺 (chk)
|
13ms |
512 KiB |
|
172 Bytes |
2022-8-30 17:33:57 |
|
Accepted (周芷乐)
|
13ms |
7 MiB |
C++14 |
205 Bytes |
2024-6-17 21:49:30 |
|
手搓STL stack 双向无环链表 _ 向量 2种实现方式: template <typename Map_Type> class Stack_l /* Stack _ List */ { private: struct Node { Map_Type Node_Data; Node *nextp, *lastp; Node(void) { nextp = 0; lastp = 0; } }; struct List_Data { unsigned int List_Size; Node *headp, *endp; List_Data(void) { List_Size = 0; headp = 0; endp = 0; } }Data; struct Vector_Data { Map_Type *headp, *lastp, *endp; void resize(unsigned int data_size) { Map_Type *newp = new Map_Type[data_size](); endp = newp + data_size - 1; lastp = newp + (data_size > lastp - headp ? lastp - headp : data_size); if (headp) delete[] headp; headp = newp; } Vector_Data(void) { headp = 0; lastp = 0; endp = 0; } }; public: unsigned int size(void) { return Data.List_Size; } Map_Type& top(void) { return Data.endp -> Node_Data; } void* data(void) { return &Data; } bool empty(void) { return !((bool)Data.headp); } Stack_l<Map_Type>& push(Map_Type push_data) { Node *nodep = new Node(); nodep -> lastp = Data.endp; if (!Data.headp) { Data.headp = nodep; Data.endp = nodep; } else Data.endp -> nextp = nodep; Data.endp = nodep; nodep -> Node_Data = push_data; ++Data.List_Size; return *this; } Stack_l<Map_Type>& push(Map_Type& push_data) { Node *nodep = new Node(); nodep -> lastp = Data.endp; if (!Data.headp) { Data.headp = nodep; Data.endp = nodep; } else Data.endp -> nextp = nodep; Data.endp = nodep; nodep -> Node_Data = push_data; ++Data.List_Size; return *this; } Stack_l<Map_Type>& push(Map_Type* push_data) { Node *nodep = new Node(); nodep -> lastp = Data.endp; if (!Data.headp) { Data.headp = nodep; Data.endp = nodep; } else Data.endp -> nextp = nodep; Data.endp = nodep; nodep -> Node_Data = *push_data; ++Data.List_Size; return *this; } Stack_l<Map_Type>& push(const Map_Type* push_data) { Node *nodep = new Node(); nodep -> lastp = Data.endp; if (!Data.headp) { Data.headp = nodep; Data.endp = nodep; } else Data.endp -> nextp = nodep; Data.endp = nodep; nodep -> Node_Data = *(Map_Type*)push_data; ++Data.List_Size; return *this; } Stack_l<Map_Type>& pop(void) { if (Data.headp) { if (Data.List_Size == 1u) { delete Data.headp; Data.List_Size = 0; Data.headp = 0; Data.endp = 0; } else { Data.endp = Data.endp -> lastp; delete Data.endp -> nextp; Data.endp -> nextp = 0; --Data.List_Size; } } return *this; } Stack_l<Map_Type>& clear(void) { while (Data.List_Size) { pop(); } return *this; } Stack_l<Map_Type>(void) { /* NULL */ } Stack_l<Map_Type>(unsigned int data_size, Map_Type map_data) { Data.List_Size = data_size; while (data_size--) { Node *nodep = new Node(); nodep -> Node_Data = map_data; if (Data.headp) { nodep -> lastp = Data.endp; Data.endp -> nextp = nodep; Data.endp = nodep; } else { Data.headp = nodep; Data.endp = nodep; } } } Stack_l<Map_Type>(Stack_l<Map_Type>& map_data) { if (!map_data.empty()) { List_Data *listp = (List_Data*)map_data.data(); Node *nodep = listp -> headp, *newp; for (unsigned int i = 0; i != listp -> List_Size; ++i, nodep = nodep -> nextp) { newp = new Node(); newp -> Node_Data = nodep -> Node_Data; if (Data.headp) { newp -> lastp = Data.endp; Data.endp -> nextp = newp; Data.endp = newp; } else { Data.headp = newp; Data.endp = newp; } } Data.List_Size = listp -> List_Size; } } Stack_l<Map_Type>& operator=(Stack_l<Map_Type>& copy_data) { if (copy_data.empty()) return *this; List_Data *listp = (List_Data*)copy_data.data(); Node *nodep = listp -> headp, *newp; for (unsigned int i = 0; i != listp -> List_Size; ++i, nodep = nodep -> nextp) { newp = new Node(); newp -> Node_Data = nodep -> Node_Data; if (Data.headp) { newp -> lastp = Data.endp; Data.endp -> nextp = newp; Data.endp = newp; } else { Data.headp = newp; Data.endp = newp; } } Data.List_Size = listp -> List_Size; return *this; } bool operator==(Stack_l<Map_Type>& cmp_data) { if (cmp_data.size() != Data.List_Size) return false; else if (cmp_data.empty() && (!Data.List_Size)) return true; Node *nodep1 = Data.headp, *nodep2 = ((List_Data*)cmp_data.data()) ->headp; for (unsigned int i = 0; i != Data.List_Size; ++i, nodep1 = nodep1 -> nextp, nodep2 = nodep2 ->nextp) { if (nodep1 -> Node_Data != nodep2 -> Node_Data) return false; } return true; } bool operator!=(Stack_l<Map_Type>& cmp_data) { if (cmp_data.size() == Data.List_Size) return false; else if (cmp_data.empty() && (!Data.List_Size)) return false; Node *nodep1 = Data.headp, *nodep2 = ((List_Data*)cmp_data.data()) ->headp; for (unsigned int i = 0; i != Data.List_Size; ++i, nodep1 = nodep1 -> nextp, nodep2 = nodep2 ->nextp) { if (nodep1 -> Node_Data != nodep2 -> Node_Data) return true; } return true; } ~Stack_l<Map_Type>(void) { clear(); } }; /* Stack _ List */ template <typename Map_Type> class Stack_v /* Stack _ Vector */ { private: struct Node { Map_Type Node_Data; Node *nextp, *lastp; Node(void) { nextp = 0; lastp = 0; } }; struct List_Data { unsigned int List_Size; Node *headp, *endp; List_Data(void) { List_Size = 0; headp = 0; endp = 0; } }; struct Vector_Data { Map_Type *headp, *lastp, *endp; void resize(unsigned int data_size) { Map_Type *newp = new Map_Type[data_size](); endp = newp + data_size - 1; lastp = newp + (data_size > lastp - headp ? lastp - headp : data_size); if (headp) delete[] headp; headp = newp; } Vector_Data(void) { headp = 0; lastp = 0; endp = 0; } }Data; public: unsigned int size(void) { return Data.lastp - Data.headp; } Map_Type& top(void) { return *(Data.lastp - 1); } void* data(void) { return &Data; } bool full(void) { if (!Data.headp) return true; return Data.endp + 1 == Data.lastp; } bool empty(void) { if (!Data.headp) return true; return Data.headp == Data.lastp; } Stack_v<Map_Type>& push(Map_Type push_data) { if (full()) Data.resize((unsigned int)((Data.lastp - Data.headp) * 1.5) + 1); *Data.lastp = push_data; ++Data.lastp; return *this; } Stack_v<Map_Type>& push(Map_Type& push_data) { if (full()) Data.resize((unsigned int)((Data.lastp - Data.headp) * 1.5) + 1); *Data.lastp = push_data; ++Data.lastp; return *this; } Stack_v<Map_Type>& push(Map_Type* push_data) { if (full()) Data.resize((unsigned int)((Data.lastp - Data.headp) * 1.5) + 1); *Data.lastp = *push_data; ++Data.lastp; return *this; } Stack_v<Map_Type>& push(const Map_Type* push_data) { if (full()) Data.resize((unsigned int)((Data.lastp - Data.headp) * 1.5) + 1); *Data.lastp = *(Map_Type*)push_data; ++Data.lastp; return *this; } Stack_v<Map_Type>& pop(void) { if (empty()) { if (Data.lastp - Data.headp > 1) Data.resize((Data.lastp - Data.headp) >> 1); else return *this; } else --Data.lastp; return *this; } Stack_v<Map_Type>(void) { /* NULL */ } Stack_v<Map_Type>(unsigned int data_size, Map_Type map_data) { while (data_size) { push(&map_data); --data_size; } } Stack_v<Map_Type>(Stack_v<Map_Type>& map_data) { Vector_Data *datap = (Vector_Data*)map_data.data(); for (unsigned int i = 0, k = map_data.size(); i != k; ++i) push(datap -> headp + i); } Stack_v<Map_Type>& operator=(Stack_v<Map_Type>& copy_data) { if (copy_data.empty()) clear(); else { Vector_Data *datap = (Vector_Data*)copy_data.data(); for (unsigned int i = 0, k = copy_data.size(); i != k; ++i) push(datap -> headp + i); } return *this; } bool operator==(Stack_v<Map_Type>& cmp_data) { if (size() != cmp_data.size()) return false; else if (empty() && cmp_data.empty()) return true; Vector_Data *datap = (Vector_Data*)cmp_data.data(); for (unsigned int i = 0, k = size(); i != k; ++i) { if (*(Data.headp + i) != *(datap ->headp + i)) return false; } return true; } bool operator!=(Stack_v<Map_Type>& cmp_data) { if (size() != cmp_data.size()) return true; else if (empty() && cmp_data.empty()) return false; Vector_Data *datap = (Vector_Data*)cmp_data.data(); for (unsigned int i = 0, k = size(); i != k; ++i) { if (*(Data.headp + i) != *(datap -> headp + i)) return true; } return false; } Stack_v<Map_Type>& clear(void) { delete[] Data.headp; Data.headp = 0; Data.lastp = 0; Data.endp = 0; return *this; } ~Stack_v<Map_Type>(void) { delete[] Data.headp; } }; /* Stack _ Vector */ int main(void) { return 0; } (22029-xys)
|
13ms |
384 KiB |
|
202 Bytes |
2023-5-20 11:17:28 |
|
明哲瀚 (18580067605)
|
13ms |
392 KiB |
|
210 Bytes |
2022-9-24 18:14:38 |
|
我全家SB!!! 我没母!!! (baijinlin)
|
13ms |
384 KiB |
|
181 Bytes |
2023-2-18 17:23:02 |
|
我推的乱破 (贺俊楠)
|
13ms |
432 KiB |
|
261 Bytes |
2023-3-5 8:39:33 |
|
何镇西1
|
13ms |
7 MiB |
C++98 |
207 Bytes |
2024-6-21 16:54:58 |
|
lafuzbc
|
13ms |
512 KiB |
|
167 Bytes |
2022-7-24 16:10:18 |
|
新壹街——陈学彬 (BUG)
|
13ms |
384 KiB |
|
153 Bytes |
2022-6-21 19:40:43 |
|
余瀚
|
13ms |
6.9 MiB |
C++11 |
246 Bytes |
2024-8-22 16:14:05 |
|
zhuxiayu
|
13ms |
6.9 MiB |
C++11 |
199 Bytes |
2024-8-22 11:03:09 |
|
明哲瀚 (18580067605)
|
13ms |
392 KiB |
|
210 Bytes |
2022-9-24 18:14:42 |
|
喵 (蹇心悦)
|
13ms |
512 KiB |
|
257 Bytes |
2022-4-30 14:05:43 |
|
吴俊成 (wujuncheng)
|
13ms |
384 KiB |
|
232 Bytes |
2022-7-8 23:15:43 |
|
Accepted (周芷乐)
|
13ms |
7 MiB |
C++14 |
205 Bytes |
2024-6-17 19:21:41 |
|
yanxiaosong
|
13ms |
384 KiB |
|
189 Bytes |
2022-4-4 20:46:56 |
|
huyinuo
|
13ms |
440 KiB |
|
197 Bytes |
2022-2-21 11:26:32 |
|
11451254188 (22029-mjh)
|
13ms |
384 KiB |
|
226 Bytes |
2023-2-22 22:12:46 |
|
宋金龙 (songjl0421)
|
13ms |
400 KiB |
|
206 Bytes |
2022-1-22 17:56:19 |
|
赵鑫宸 (xiaoxiao721)
|
13ms |
420 KiB |
|
220 Bytes |
2022-2-20 3:00:45 |
|
我是撒bi (pyf)
|
13ms |
384 KiB |
|
258 Bytes |
2022-4-30 16:16:06 |
|
凌肯 (lingken22006)
|
13ms |
384 KiB |
|
168 Bytes |
2022-7-23 22:38:21 |
|
郭人瑀作业号
|
13ms |
432 KiB |
|
208 Bytes |
2022-8-2 16:40:17 |
|
lafuzbc
|
13ms |
392 KiB |
|
167 Bytes |
2022-7-24 16:10:16 |
|
朱老师 (zyp)
|
13ms |
440 KiB |
|
187 Bytes |
2022-7-27 0:46:34 |
|
panyan
|
13ms |
384 KiB |
|
177 Bytes |
2022-4-30 14:10:31 |
|
hnd (陈皓洋)
|
13ms |
384 KiB |
|
281 Bytes |
2022-8-15 19:00:50 |
|
﹢•﹡🕉☽✝⚜Halanfus⚜✝☾⚔⚝﹡﹢• (黄子瑞)
|
13ms |
6.9 MiB |
|
165 Bytes |
2023-7-28 15:21:15 |
|
我全家SB!!! 我没母!!! (baijinlin)
|
13ms |
384 KiB |
|
181 Bytes |
2023-2-18 17:23:02 |
|
陈红恺 (chk)
|
13ms |
384 KiB |
|
172 Bytes |
2022-8-30 17:34:04 |
|
18523558128zcn
|
13ms |
392 KiB |
|
240 Bytes |
2022-4-9 14:40:21 |
|
陈杰晟
|
13ms |
440 KiB |
|
226 Bytes |
2022-2-18 13:29:32 |
|
Mr.zou(邹镇宇小号)
|
13ms |
384 KiB |
|
181 Bytes |
2023-4-3 20:58:59 |
|
凌肯 (lingken22006)
|
13ms |
392 KiB |
|
168 Bytes |
2022-7-23 22:38:21 |
|
我全家SB!!! 我没母!!! (baijinlin)
|
13ms |
392 KiB |
|
181 Bytes |
2023-2-18 17:23:02 |
|
lll
|
13ms |
512 KiB |
|
144 Bytes |
2022-9-6 11:48:31 |
|
(张洛诚)
|
13ms |
512 KiB |
|
358 Bytes |
2023-3-4 18:54:20 |
|
时代二校-杨林老师-黄浦轩 (黄px)
|
13ms |
6.8 MiB |
C++11 |
167 Bytes |
2024-8-9 17:06:04 |
|
姚宏逸
|
13ms |
384 KiB |
|
191 Bytes |
2022-2-28 22:53:06 |
|
陈秋石
|
13ms |
384 KiB |
|
191 Bytes |
2022-2-27 11:36:24 |
|
我全家SB!!! 我没母!!! (baijinlin)
|
13ms |
384 KiB |
|
181 Bytes |
2023-2-18 17:23:00 |
|
低调的学霸
|
13ms |
432 KiB |
|
213 Bytes |
2022-8-20 16:12:20 |
|
我全家SB!!! 我没母!!! (baijinlin)
|
13ms |
384 KiB |
|
181 Bytes |
2023-2-18 17:23:03 |
|
逄云皓
|
13ms |
6.8 MiB |
C++98 |
174 Bytes |
2024-8-25 15:06:49 |
|
罗翌珂 (dangdang)
|
13ms |
384 KiB |
|
192 Bytes |
2022-8-11 20:56:44 |
|
无尽的想象 (谭仕高)
|
13ms |
444 KiB |
|
180 Bytes |
2022-7-12 17:58:14 |
|
zhangxiushi
|
13ms |
384 KiB |
|
257 Bytes |
2022-1-22 19:06:50 |
|
陈红恺 (chk)
|
13ms |
384 KiB |
|
172 Bytes |
2022-8-30 17:34:00 |
|
tsc_ (杨悦堃)
|
13ms |
388 KiB |
|
198 Bytes |
2023-2-22 19:35:44 |
|
yiqiuyu
|
13ms |
384 KiB |
|
183 Bytes |
2023-2-18 17:24:24 |
|
yaokaixuan
|
13ms |
392 KiB |
|
241 Bytes |
2022-1-18 14:38:44 |
|
lafuzbc
|
13ms |
392 KiB |
|
167 Bytes |
2022-7-24 16:10:17 |
|
夏麟然
|
13ms |
6.9 MiB |
C++98 |
171 Bytes |
2024-5-24 18:04:20 |
|
暗蛆突围 (lzh)
|
13ms |
6.8 MiB |
|
218 Bytes |
2023-10-29 0:11:46 |
|
0721 (龙浩恩)
|
13ms |
6.9 MiB |
|
267 Bytes |
2023-10-29 11:58:48 |
|
SMIK
|
13ms |
384 KiB |
|
244 Bytes |
2022-1-24 12:33:01 |
|
luojunyang
|
13ms |
392 KiB |
|
193 Bytes |
2022-1-21 18:56:09 |
|
赵彬鸿
|
13ms |
384 KiB |
|
153 Bytes |
2022-8-12 15:42:32 |
|
吵吵小小 (超级小白)
|
13ms |
384 KiB |
|
184 Bytes |
2023-2-19 15:50:07 |
|
我全家SB!!! 我没母!!! (baijinlin)
|
13ms |
384 KiB |
|
181 Bytes |
2023-2-18 17:23:01 |
|
城 (liqc)
|
13ms |
6.8 MiB |
|
436 Bytes |
2023-10-5 11:54:57 |
|
汪致卉 (wangzh)
|
13ms |
384 KiB |
|
286 Bytes |
2022-1-22 18:53:06 |
|
陈红恺 (chk)
|
13ms |
512 KiB |
|
172 Bytes |
2022-8-30 17:33:39 |
|
肖添宇
|
13ms |
388 KiB |
|
386 Bytes |
2022-3-19 18:02:20 |
|
田雨杨 (tianyuyang23010)
|
13ms |
7.2 MiB |
C++98 |
223 Bytes |
2024-5-10 20:40:12 |
|
🖕🖕🖕🖕🖕🖕🖕🖕🖕🖕🖕🖕🖕🖕🖕🖕🖕🖕🖕🖕🖕🖕🖕🖕🖕🖕🖕🖕🖕🖕🖕🖕🖕🖕🖕🖕🖕🖕🖕🖕🖕 (bro)
|
13ms |
384 KiB |
|
303 Bytes |
2022-1-25 15:53:38 |
|
zhoumingze23017
|
13ms |
6.6 MiB |
|
202 Bytes |
2023-9-21 21:53:06 |
|
05c30-dyh
|
13ms |
512 KiB |
|
265 Bytes |
2022-2-19 16:05:05 |
|
lafuzbc
|
13ms |
384 KiB |
|
167 Bytes |
2022-7-24 16:10:19 |
|
冯若涵
|
13ms |
6.9 MiB |
|
204 Bytes |
2023-11-4 10:30:17 |
|
heyuzhe
|
13ms |
7 MiB |
C++98 |
193 Bytes |
2024-6-19 19:23:22 |
|
祝熙承 (zxc)
|
13ms |
392 KiB |
|
204 Bytes |
2022-4-9 15:59:28 |
|
lafuzbc
|
13ms |
384 KiB |
|
167 Bytes |
2022-7-24 16:10:29 |
|
zhanghaoran
|
13ms |
384 KiB |
|
285 Bytes |
2022-1-23 11:31:12 |
|
杨淇瑞 (杨淇瑞29)
|
13ms |
384 KiB |
|
232 Bytes |
2023-4-19 20:37:17 |
|
赵彬鸿
|
13ms |
384 KiB |
|
153 Bytes |
2022-8-12 15:42:38 |
|
zhanglianjie
|
13ms |
384 KiB |
|
178 Bytes |
2023-2-18 17:34:14 |
|
灿灿 (CAN)
|
13ms |
384 KiB |
|
333 Bytes |
2022-5-29 11:53:05 |
|
陈红恺 (chk)
|
13ms |
512 KiB |
|
172 Bytes |
2022-8-30 17:33:39 |
|
吴攸 (wuyou)
|
13ms |
384 KiB |
|
183 Bytes |
2023-2-19 15:45:49 |
|
火爆肥肠(杨弘毅) (火爆肥肠)
|
13ms |
384 KiB |
|
240 Bytes |
2022-3-1 21:54:01 |
|
支彦淇
|
13ms |
384 KiB |
|
176 Bytes |
2022-10-5 14:54:56 |
|
何星震 (Jacob)
|
13ms |
392 KiB |
|
203 Bytes |
2022-10-6 14:53:33 |
|
17779
|
13ms |
384 KiB |
|
199 Bytes |
2022-3-8 14:53:44 |
|
葛广言
|
13ms |
7.2 MiB |
C++98 |
154 Bytes |
2024-4-24 19:03:29 |
|
陈于硕(我™的) (chenyu)
|
14ms |
512 KiB |
|
166 Bytes |
2023-3-4 9:28:16 |
|
江子墨
|
14ms |
6.8 MiB |
C++98 |
170 Bytes |
2024-6-7 15:42:11 |
|
孙嘉蔚
|
14ms |
6.9 MiB |
C++11 |
199 Bytes |
2024-6-28 17:52:43 |
|
黄梓桐 (HuangZiTong)
|
14ms |
516 KiB |
|
227 Bytes |
2022-6-26 21:47:20 |
|
我全家SB!!! 我没母!!! (baijinlin)
|
14ms |
384 KiB |
|
181 Bytes |
2023-2-18 17:23:03 |
|
星野 光 (Hoshino Hikari)
|
14ms |
6.8 MiB |
|
253 Bytes |
2023-10-20 22:03:02 |
|
laiyouming22031
|
14ms |
384 KiB |
|
214 Bytes |
2022-10-2 11:47:39 |
|
22029-lyh
|
14ms |
432 KiB |
|
226 Bytes |
2023-3-23 18:44:24 |
|
余彦瑞
|
14ms |
512 KiB |
|
201 Bytes |
2022-2-27 11:28:25 |
|
lyc2
|
14ms |
512 KiB |
|
182 Bytes |
2022-4-9 20:34:47 |
|
低调的学霸
|
14ms |
412 KiB |
|
213 Bytes |
2022-8-20 16:12:24 |
|
lafuzbc
|
14ms |
512 KiB |
|
167 Bytes |
2022-7-24 16:10:12 |