QUEUE

Constant QUEUE 

Source
pub const QUEUE: &str = "// stdlib/queue.aether\n// Aether \u{961f}\u{5217}\u{ff08}Queue\u{ff09}\u{6570}\u{636e}\u{7ed3}\u{6784}\u{5e93}\n// \u{5b9e}\u{73b0}\u{5148}\u{8fdb}\u{5148}\u{51fa}\u{ff08}FIFO\u{ff09}\u{961f}\u{5217}\u{ff0c}\u{4f7f}\u{7528}\u{6570}\u{7ec4}\u{5b9e}\u{73b0}\n\n// ==================== \u{521b}\u{5efa}\u{961f}\u{5217} ====================\n\n// \u{521b}\u{5efa}\u{4e00}\u{4e2a}\u{7a7a}\u{961f}\u{5217}\nFunc QUEUE_NEW() {\n    Return []\n}\n\n// \u{4ece}\u{6570}\u{7ec4}\u{521b}\u{5efa}\u{961f}\u{5217}\nFunc QUEUE_FROM_ARRAY(ARR) {\n    Return ARR\n}\n\n// ==================== \u{57fa}\u{672c}\u{64cd}\u{4f5c} ====================\n\n// \u{5165}\u{961f}\u{ff1a}\u{5728}\u{961f}\u{5c3e}\u{6dfb}\u{52a0}\u{5143}\u{7d20}\n// \u{8fd4}\u{56de}\u{65b0}\u{7684}\u{961f}\u{5217}\nFunc QUEUE_ENQUEUE(QUEUE, ITEM) {\n    Return PUSH(QUEUE, ITEM)\n}\n\n// \u{51fa}\u{961f}\u{ff1a}\u{79fb}\u{9664}\u{5e76}\u{8fd4}\u{56de}\u{961f}\u{9996}\u{5143}\u{7d20}\n// \u{8fd4}\u{56de}\u{4e00}\u{4e2a}\u{5b57}\u{5178}\u{ff1a}{\"queue\": \u{65b0}\u{961f}\u{5217}, \"value\": \u{51fa}\u{961f}\u{7684}\u{503c}}\n// \u{5982}\u{679c}\u{961f}\u{5217}\u{4e3a}\u{7a7a}\u{ff0c}\u{8fd4}\u{56de} {\"queue\": [], \"value\": Null}\nFunc QUEUE_DEQUEUE(QUEUE) {\n    If (QUEUE_IS_EMPTY(QUEUE)) {\n        Return {\"queue\": [], \"value\": Null}\n    }\n    \n    Set FIRST QUEUE[0]\n    Set NEW_QUEUE []\n    Set LEN_ LEN(QUEUE)\n    Set I 1\n    \n    While (I < LEN_) {\n        Set NEW_QUEUE PUSH(NEW_QUEUE, QUEUE[I])\n        Set I (I + 1)\n    }\n    \n    Return {\"queue\": NEW_QUEUE, \"value\": FIRST}\n}\n\n// \u{67e5}\u{770b}\u{961f}\u{9996}\u{5143}\u{7d20}\u{ff08}\u{4e0d}\u{79fb}\u{9664}\u{ff09}\nFunc QUEUE_PEEK(QUEUE) {\n    If (QUEUE_IS_EMPTY(QUEUE)) {\n        Return Null\n    }\n    Return QUEUE[0]\n}\n\n// \u{67e5}\u{770b}\u{961f}\u{5c3e}\u{5143}\u{7d20}\nFunc QUEUE_PEEK_BACK(QUEUE) {\n    If (QUEUE_IS_EMPTY(QUEUE)) {\n        Return Null\n    }\n    Set LEN_ LEN(QUEUE)\n    Return QUEUE[LEN_ - 1]\n}\n\n// \u{83b7}\u{53d6}\u{961f}\u{5217}\u{5927}\u{5c0f}\nFunc QUEUE_SIZE(QUEUE) {\n    Return LEN(QUEUE)\n}\n\n// \u{68c0}\u{67e5}\u{961f}\u{5217}\u{662f}\u{5426}\u{4e3a}\u{7a7a}\nFunc QUEUE_IS_EMPTY(QUEUE) {\n    Return LEN(QUEUE) == 0\n}\n\n// \u{6e05}\u{7a7a}\u{961f}\u{5217}\nFunc QUEUE_CLEAR() {\n    Return []\n}\n\n// ==================== \u{9ad8}\u{7ea7}\u{64cd}\u{4f5c} ====================\n\n// \u{68c0}\u{67e5}\u{961f}\u{5217}\u{662f}\u{5426}\u{5305}\u{542b}\u{5143}\u{7d20}\nFunc QUEUE_CONTAINS(QUEUE, ITEM) {\n    Set LEN_ LEN(QUEUE)\n    Set I 0\n    \n    While (I < LEN_) {\n        If (QUEUE[I] == ITEM) {\n            Return True\n        }\n        Set I (I + 1)\n    }\n    \n    Return False\n}\n\n// \u{83b7}\u{53d6}\u{5143}\u{7d20}\u{5728}\u{961f}\u{5217}\u{4e2d}\u{7684}\u{4f4d}\u{7f6e}\u{ff08}\u{4ece}0\u{5f00}\u{59cb}\u{ff09}\u{ff0c}\u{5982}\u{679c}\u{4e0d}\u{5b58}\u{5728}\u{8fd4}\u{56de} -1\nFunc QUEUE_INDEX_OF(QUEUE, ITEM) {\n    Set LEN_ LEN(QUEUE)\n    Set I 0\n    \n    While (I < LEN_) {\n        If (QUEUE[I] == ITEM) {\n            Return I\n        }\n        Set I (I + 1)\n    }\n    \n    Return -1\n}\n\n// \u{5c06}\u{961f}\u{5217}\u{8f6c}\u{6362}\u{4e3a}\u{6570}\u{7ec4}\nFunc QUEUE_TO_ARRAY(QUEUE) {\n    Return QUEUE\n}\n\n// \u{53cd}\u{8f6c}\u{961f}\u{5217}\nFunc QUEUE_REVERSE(QUEUE) {\n    Set RESULT []\n    Set LEN_ LEN(QUEUE)\n    Set I (LEN_ - 1)\n    \n    While (I >= 0) {\n        Set RESULT PUSH(RESULT, QUEUE[I])\n        Set I (I - 1)\n    }\n    \n    Return RESULT\n}\n\n// ==================== \u{6279}\u{91cf}\u{64cd}\u{4f5c} ====================\n\n// \u{6279}\u{91cf}\u{5165}\u{961f}\u{ff1a}\u{5c06}\u{6570}\u{7ec4}\u{4e2d}\u{7684}\u{6240}\u{6709}\u{5143}\u{7d20}\u{52a0}\u{5165}\u{961f}\u{5217}\nFunc QUEUE_ENQUEUE_ALL(QUEUE, ARR) {\n    Set RESULT QUEUE\n    Set LEN_ LEN(ARR)\n    Set I 0\n    \n    While (I < LEN_) {\n        Set RESULT PUSH(RESULT, ARR[I])\n        Set I (I + 1)\n    }\n    \n    Return RESULT\n}\n\n// \u{6279}\u{91cf}\u{51fa}\u{961f}\u{ff1a}\u{79fb}\u{9664}\u{5e76}\u{8fd4}\u{56de}\u{6307}\u{5b9a}\u{6570}\u{91cf}\u{7684}\u{5143}\u{7d20}\n// \u{8fd4}\u{56de}\u{4e00}\u{4e2a}\u{5b57}\u{5178}\u{ff1a}{\"queue\": \u{65b0}\u{961f}\u{5217}, \"values\": \u{51fa}\u{961f}\u{7684}\u{5143}\u{7d20}\u{6570}\u{7ec4}}\nFunc QUEUE_DEQUEUE_N(QUEUE, N) {\n    If (N <= 0) {\n        Return {\"queue\": QUEUE, \"values\": []}\n    }\n    \n    Set MAX_N N\n    Set LEN_ LEN(QUEUE)\n    If (N > LEN_) {\n        Set MAX_N LEN_\n    }\n    \n    Set VALUES []\n    Set I 0\n    \n    While (I < MAX_N) {\n        Set VALUES PUSH(VALUES, QUEUE[I])\n        Set I (I + 1)\n    }\n    \n    Set NEW_QUEUE []\n    Set J MAX_N\n    \n    While (J < LEN_) {\n        Set NEW_QUEUE PUSH(NEW_QUEUE, QUEUE[J])\n        Set J (J + 1)\n    }\n    \n    Return {\"queue\": NEW_QUEUE, \"values\": VALUES}\n}\n\n// ==================== \u{5b9e}\u{7528}\u{51fd}\u{6570} ====================\n\n// \u{904d}\u{5386}\u{961f}\u{5217}\u{ff0c}\u{5bf9}\u{6bcf}\u{4e2a}\u{5143}\u{7d20}\u{5e94}\u{7528}\u{51fd}\u{6570}\n// FUNC \u{5e94}\u{8be5}\u{63a5}\u{53d7}\u{4e24}\u{4e2a}\u{53c2}\u{6570}\u{ff08}\u{7d22}\u{5f15}\u{ff0c}\u{5143}\u{7d20}\u{ff09}\nFunc QUEUE_FOREACH(QUEUE, FUNC) {\n    Set LEN_ LEN(QUEUE)\n    Set I 0\n    \n    While (I < LEN_) {\n        FUNC(I, QUEUE[I])\n        Set I (I + 1)\n    }\n}\n\n// \u{8fc7}\u{6ee4}\u{961f}\u{5217}\u{ff0c}\u{8fd4}\u{56de}\u{6ee1}\u{8db3}\u{6761}\u{4ef6}\u{7684}\u{5143}\u{7d20}\u{7ec4}\u{6210}\u{7684}\u{65b0}\u{961f}\u{5217}\n// PREDICATE \u{5e94}\u{8be5}\u{63a5}\u{53d7}\u{4e00}\u{4e2a}\u{53c2}\u{6570}\u{5e76}\u{8fd4}\u{56de} True/False\nFunc QUEUE_FILTER(QUEUE, PREDICATE) {\n    Set RESULT []\n    Set LEN_ LEN(QUEUE)\n    Set I 0\n    \n    While (I < LEN_) {\n        Set ITEM QUEUE[I]\n        If (PREDICATE(ITEM)) {\n            Set RESULT PUSH(RESULT, ITEM)\n        }\n        Set I (I + 1)\n    }\n    \n    Return RESULT\n}\n\n// \u{6620}\u{5c04}\u{961f}\u{5217}\u{ff0c}\u{5bf9}\u{6bcf}\u{4e2a}\u{5143}\u{7d20}\u{5e94}\u{7528}\u{51fd}\u{6570}\u{ff0c}\u{8fd4}\u{56de}\u{65b0}\u{961f}\u{5217}\n// MAPPER \u{5e94}\u{8be5}\u{63a5}\u{53d7}\u{4e00}\u{4e2a}\u{53c2}\u{6570}\u{5e76}\u{8fd4}\u{56de}\u{8f6c}\u{6362}\u{540e}\u{7684}\u{503c}\nFunc QUEUE_MAP(QUEUE, MAPPER) {\n    Set RESULT []\n    Set LEN_ LEN(QUEUE)\n    Set I 0\n    \n    While (I < LEN_) {\n        Set RESULT PUSH(RESULT, MAPPER(QUEUE[I]))\n        Set I (I + 1)\n    }\n    \n    Return RESULT\n}\n\n// \u{5c06}\u{961f}\u{5217}\u{8f6c}\u{6362}\u{4e3a}\u{5b57}\u{7b26}\u{4e32}\u{8868}\u{793a}\nFunc QUEUE_TO_STRING(QUEUE) {\n    If (QUEUE_IS_EMPTY(QUEUE)) {\n        Return \"Queue[]\"\n    }\n    \n    Set RESULT \"Queue[\"\n    Set LEN_ LEN(QUEUE)\n    Set I 0\n    \n    While (I < LEN_) {\n        Set RESULT (RESULT + TO_STRING(QUEUE[I]))\n        If (I < (LEN_ - 1)) {\n            Set RESULT (RESULT + \", \")\n        }\n        Set I (I + 1)\n    }\n    \n    Set RESULT (RESULT + \"]\")\n    Return RESULT\n}\n\n// \u{5408}\u{5e76}\u{4e24}\u{4e2a}\u{961f}\u{5217}\nFunc QUEUE_CONCAT(QUEUE1, QUEUE2) {\n    Return QUEUE_ENQUEUE_ALL(QUEUE1, QUEUE2)\n}\n";
Expand description

队列(Queue)数据结构