|
Tang
|
3ms |
440 KiB |
|
199 Bytes |
2022-2-13 11:12:35 |
|
手搓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)
|
3ms |
440 KiB |
|
193 Bytes |
2023-5-12 20:22:33 |
|
戴渝晋
|
3ms |
392 KiB |
|
181 Bytes |
2023-3-14 18:25:31 |
|
游智棋
|
3ms |
7.1 MiB |
|
172 Bytes |
2023-7-18 11:46:39 |
|
胡澜之 (666hlz666)
|
3ms |
7.1 MiB |
|
193 Bytes |
2023-7-9 9:34:43 |
|
colin1112 (墙凌可)
|
3ms |
432 KiB |
|
235 Bytes |
2023-1-22 12:30:16 |
|
张承暄
|
3ms |
7.2 MiB |
|
150 Bytes |
2023-7-2 16:55:23 |
|
李荣轩
|
3ms |
384 KiB |
|
176 Bytes |
2023-3-14 18:19:04 |
|
李霄麒
|
3ms |
392 KiB |
|
180 Bytes |
2023-3-14 18:24:52 |
|
张家赫
|
3ms |
428 KiB |
|
281 Bytes |
2023-3-14 18:17:26 |
|
李霄麒
|
3ms |
384 KiB |
|
180 Bytes |
2023-3-14 18:24:58 |
|
李霄麒
|
3ms |
384 KiB |
|
180 Bytes |
2023-3-14 18:24:52 |
|
马渝杭 (mayuhang)
|
3ms |
404 KiB |
|
165 Bytes |
2023-1-14 12:06:28 |
|
戴渝晋
|
3ms |
384 KiB |
|
181 Bytes |
2023-3-14 18:25:31 |
|
徐宛婷
|
3ms |
384 KiB |
|
186 Bytes |
2023-3-14 18:27:14 |
|
黄彦熹 (AK-203)
|
3ms |
440 KiB |
|
164 Bytes |
2022-10-26 11:58:00 |
|
程曦漫
|
3ms |
6.7 MiB |
|
154 Bytes |
2023-9-19 20:02:00 |
|
罗竣瀚
|
3ms |
384 KiB |
|
157 Bytes |
2022-10-16 14:59:24 |
|
李霄麒
|
3ms |
384 KiB |
|
180 Bytes |
2023-3-14 18:24:56 |
|
黎湘渝
|
3ms |
392 KiB |
|
175 Bytes |
2023-3-14 18:30:23 |
|
冒牌陈杰晟【MOD】 (wed)
|
3ms |
428 KiB |
|
126 Bytes |
2022-2-25 19:09:46 |
|
新壹街——陈学彬 (BUG)
|
3ms |
7.4 MiB |
|
149 Bytes |
2023-7-10 9:53:49 |
|
甄一阳 (22016-zyy)
|
3ms |
440 KiB |
|
188 Bytes |
2022-11-27 11:44:06 |
|
时代一校-赵彦博 (zyb)
|
3ms |
6.9 MiB |
|
173 Bytes |
2023-7-11 21:38:25 |
|
wangjunhan
|
3ms |
436 KiB |
|
176 Bytes |
2022-8-31 9:46:09 |
|
黎湘渝
|
3ms |
360 KiB |
|
175 Bytes |
2023-3-14 18:30:35 |
|
繁星 (05c35-zzm)
|
3ms |
440 KiB |
|
183 Bytes |
2022-10-31 19:17:14 |
|
李霄麒
|
3ms |
384 KiB |
|
180 Bytes |
2023-3-14 18:24:55 |
|
RanHao
|
3ms |
6.9 MiB |
|
159 Bytes |
2023-7-21 14:56:52 |
|
源著校区-宋昊成 (马冬梅)
|
3ms |
432 KiB |
|
167 Bytes |
2023-2-25 17:56:07 |
|
yanglang
|
3ms |
436 KiB |
|
152 Bytes |
2022-10-21 16:31:41 |
|
左雨航
|
3ms |
420 KiB |
|
180 Bytes |
2023-3-14 18:21:41 |
|
左雨航
|
3ms |
384 KiB |
|
180 Bytes |
2023-3-14 18:21:48 |
|
科比.布莱恩特 (董浩琰)
|
3ms |
6.9 MiB |
|
565 Bytes |
2023-7-21 9:55:32 |
|
徐宛婷
|
3ms |
392 KiB |
|
186 Bytes |
2023-3-14 18:27:21 |
|
除了我全部人都是SB (车涌樯)
|
3ms |
7 MiB |
|
155 Bytes |
2023-7-13 17:54:40 |
|
贾鑫豪 (Mr Sam)
|
3ms |
428 KiB |
|
171 Bytes |
2022-8-28 11:05:28 |
|
金沙校区-李嘉齐 (李嘉齐)
|
3ms |
6.9 MiB |
|
171 Bytes |
2023-8-19 11:19:47 |
|
徐宛婷
|
3ms |
404 KiB |
|
186 Bytes |
2023-3-14 18:27:20 |
|
黎湘渝
|
3ms |
392 KiB |
|
175 Bytes |
2023-3-14 18:30:21 |
|
徐宛婷
|
3ms |
384 KiB |
|
186 Bytes |
2023-3-14 18:30:12 |
|
CK (李弘毅)
|
3ms |
6.9 MiB |
|
176 Bytes |
2023-8-15 7:48:26 |
|
谭红中 (不知道)
|
3ms |
436 KiB |
|
192 Bytes |
2023-1-9 11:40:48 |
|
黎湘渝
|
3ms |
384 KiB |
|
175 Bytes |
2023-3-14 18:30:34 |
|
JOKER (hhy)
|
3ms |
436 KiB |
|
167 Bytes |
2023-5-3 18:54:13 |
|
新壹街-王俊博 (王俊博)
|
3ms |
7 MiB |
|
132 Bytes |
2023-7-10 11:57:47 |
|
执剑人罗辑 (Jasson)
|
3ms |
440 KiB |
|
140 Bytes |
2023-1-14 21:22:01 |
|
黎湘渝
|
3ms |
384 KiB |
|
175 Bytes |
2023-3-14 18:30:20 |
|
稻妻第一深情 (喝酒の吟游诗人)
|
3ms |
432 KiB |
|
1.2 KiB |
2023-1-10 15:20:03 |
|
chaikexu
|
3ms |
440 KiB |
|
155 Bytes |
2023-3-27 20:20:48 |
|
黎湘渝
|
3ms |
384 KiB |
|
175 Bytes |
2023-3-14 18:30:20 |
|
黎湘渝
|
3ms |
392 KiB |
|
175 Bytes |
2023-3-14 18:30:36 |
|
徐宛婷
|
3ms |
392 KiB |
|
186 Bytes |
2023-3-14 18:27:20 |
|
黎湘渝
|
3ms |
392 KiB |
|
175 Bytes |
2023-3-14 18:30:24 |
|
tad (OP AI)
|
3ms |
6.9 MiB |
C++98 |
159 Bytes |
2024-6-16 15:34:07 |
|
黎湘渝
|
3ms |
384 KiB |
|
175 Bytes |
2023-3-14 18:30:21 |
|
黎湘渝
|
3ms |
436 KiB |
|
175 Bytes |
2023-3-14 18:30:19 |
|
wuzhenghan
|
3ms |
492 KiB |
|
176 Bytes |
2022-11-2 21:32:14 |
|
黎湘渝
|
3ms |
384 KiB |
|
175 Bytes |
2023-3-14 18:30:19 |
|
11451254188 (22029-mjh)
|
3ms |
444 KiB |
|
161 Bytes |
2022-11-12 16:47:23 |
|
李霄麒
|
3ms |
384 KiB |
|
180 Bytes |
2023-3-14 18:24:52 |
|
新壹街陈科言 (cky)
|
3ms |
7.1 MiB |
|
167 Bytes |
2023-7-19 11:11:54 |
|
22029-zjs
|
3ms |
6.8 MiB |
|
185 Bytes |
2023-6-10 9:53:50 |
|
guozuming
|
3ms |
436 KiB |
|
139 Bytes |
2023-1-25 22:23:10 |
|
南坪校区-郑力博 (zhenglibo23003)
|
4ms |
432 KiB |
|
138 Bytes |
2023-3-13 20:51:06 |
|
李霄麒
|
4ms |
384 KiB |
|
180 Bytes |
2023-3-14 18:24:56 |
|
李霄麒
|
4ms |
384 KiB |
|
180 Bytes |
2023-3-14 18:24:55 |
|
xflt_dyp
|
4ms |
6.9 MiB |
|
183 Bytes |
2023-7-22 16:17:30 |
|
Jack
|
4ms |
448 KiB |
|
149 Bytes |
2023-1-15 20:08:28 |
|
叶雨昊 (yeyuhao22006)
|
4ms |
428 KiB |
|
176 Bytes |
2023-3-24 18:31:14 |
|
曾龙兮
|
4ms |
432 KiB |
|
159 Bytes |
2023-3-12 19:44:10 |
|
李歆颜 (llxy)
|
4ms |
6.9 MiB |
|
176 Bytes |
2023-8-4 19:38:46 |
|
李霄麒
|
4ms |
384 KiB |
|
180 Bytes |
2023-3-14 18:24:53 |
|
李霄麒
|
4ms |
384 KiB |
|
180 Bytes |
2023-3-14 18:24:57 |
|
陌生人 (涂玉龙)
|
4ms |
7 MiB |
|
154 Bytes |
2023-12-31 15:30:48 |
|
jighghjkfkhfdhdfdfdsfsdfsafvmnkbnkbmnlvnmkbvnvb;,.m;,;.;,;kbvlmkbnlmkblnvkmlbnkmlbvkmlbvklmbkmlkblmbnm;,l.,.;,'.,';.[',;.[,kjkoihgfhfgiohifgohifgohiofgihgofhiofgihofgihofgihofgiho;''[;.',m;.',m.;',.;'m,.;';'cv;x'cb'cx;b'cv;b'xc;b'c;b'cvbvc.'bv.//,/vb./vcb./cvbv,c.b,cv.,b.cv,b.vc,bg;hgl;hgl;hg;h;hfg;hl;lf;l;lxc;cln;bvln;vcln;vnl;vbl;vbln;vlv;blnvb;plnp;lplhfljpjh;nlvb;nv;bn;vcvl;nlv;nlv;g;hjhchl;ghfghl;fghl;ltlh;l;hlf;lg;bnlc;;nlv;nbv;nbv;nvb;nlvcnl;xc;blxcb;ll;hg;lhgl;dfl;t;ldy;l;lyl;rewlt493;l;dl;dsflg;lsdlpbpcxobpocvbpopopopreopotpreotertertretert (litingxu)
|
4ms |
440 KiB |
|
182 Bytes |
2023-4-16 16:16:50 |
|
煞笔笔
|
4ms |
6.9 MiB |
|
136 Bytes |
2023-11-28 19:12:02 |
|
luojunyang
|
4ms |
684 KiB |
|
262 Bytes |
2022-1-21 18:22:52 |
|
李霄麒
|
4ms |
384 KiB |
|
180 Bytes |
2023-3-14 18:24:53 |
|
U城校区-郭旻哲 (郭旻哲)
|
4ms |
7.1 MiB |
|
181 Bytes |
2023-12-28 18:31:41 |
|
李霄麒
|
4ms |
384 KiB |
|
180 Bytes |
2023-3-14 18:24:54 |
|
李霄麒
|
4ms |
384 KiB |
|
180 Bytes |
2023-3-14 18:24:57 |
|
pandap&a王皓宸 (WANGHAOCHEN)
|
4ms |
440 KiB |
|
134 Bytes |
2022-12-9 19:32:18 |
|
吴宗骏
|
4ms |
6.8 MiB |
|
201 Bytes |
2023-12-2 9:42:12 |
|
scallway1
|
4ms |
440 KiB |
|
249 Bytes |
2023-3-14 18:10:29 |
|
南坪校区-龙浩睿 (longhaorui)
|
4ms |
7 MiB |
|
171 Bytes |
2023-12-31 16:24:25 |
|
李霄麒
|
4ms |
384 KiB |
|
180 Bytes |
2023-3-14 18:24:56 |
|
cola
|
4ms |
6.6 MiB |
|
217 Bytes |
2023-11-22 17:07:40 |
|
黎湘渝
|
4ms |
384 KiB |
|
175 Bytes |
2023-3-14 18:23:16 |
|
李霄麒
|
4ms |
384 KiB |
|
180 Bytes |
2023-3-14 18:24:58 |
|
李霄麒
|
4ms |
384 KiB |
|
180 Bytes |
2023-3-14 18:24:53 |
|
时代一校 蒋帛希 (13983392730)
|
5ms |
440 KiB |
|
139 Bytes |
2022-10-13 21:25:57 |
|
AI创客
|
5ms |
7 MiB |
|
140 Bytes |
2023-11-18 17:17:22 |
|
李霄麒
|
5ms |
384 KiB |
|
180 Bytes |
2023-3-14 18:24:54 |
|
赵奕铭
|
8ms |
7 MiB |
|
160 Bytes |
2023-12-30 19:09:59 |
|
陈诺
|
8ms |
7 MiB |
|
155 Bytes |
2023-12-19 16:59:51 |
|
金沙校区-先珂熠 (九转大肠)
|
8ms |
7.1 MiB |
|
147 Bytes |
2024-1-1 19:17:14 |
|
zyl
|
8ms |
7.3 MiB |
|
142 Bytes |
2024-1-3 16:59:18 |
|
e^(i×π)+1=0
|
8ms |
7.1 MiB |
|
151 Bytes |
2024-1-17 22:02:24 |
|
K517
|
8ms |
7.3 MiB |
|
176 Bytes |
2024-1-17 16:24:50 |