Iterator

Date Tags Python

Iterator

iterator

iter(): 接收的是可迭代对象,返回的是迭代器。

next(): 接收的是迭代器,调用的是迭代器对象中的next函数,返回数据元素。

由于生成 …

more ...


A* Heuristic Algorithm

content
    #include <algorithm>  // for sort
    #include <fstream>
    #include <iostream>
    #include <sstream>
    #include <string>
    #include <vector>
    using std::cout;
    using std::ifstream;
    using std::istringstream;
    using std::sort;
    using std::string;
    using std::vector;
    using std::abs;
    
    // TODO: Add kStart and KFinish enumerators to the State enum.
    enum class State {kStart …
    more ...

    Sort

    Quick Sort

    引例:荷兰国旗问题

    Merge Sort

    class Solution {
    public:
        ListNode* sortList(ListNode* head) {
            if (head == nullptr || head->next == nullptr) { return head; }
            ListNode* fast = head;
            ListNode* slow = head;
            while (fast->next && fast->next->next) {
                slow = slow->next;
                fast = fast->next->next;
            }
            fast = slow->next;
            slow …
    more ...

    C++

    Date Tags C++

    1. 基于对象的程序设计

    只包含单一类的程序设计,存在两种类型的类的设计思想:是否含有指针成员。

    编写类class的良好习 …

    more ...

    LinkedList

    GitHub LinkedList

    链表结点定义

    class ListNode{
        public:
            int val;
            ListNode* next;
    
            ListNode() : val(0), next(nullptr) {}
            ListNode(int x) : val(x), next(nullptr) {}
            ListNode(int x, ListNode* next) : val(x), next(next) {}
    };
    

    链表基本操作

    链表的基本操作与 …

    more ...

    【RL】Q Learning

    import numpy as np
    import gym
    import random
    import time
    from IPython.display import clear_output
    
    """Creating the Environment"""
    env = gym.make("FrozenLake-v0")
    
    """Creating the Q-Table and initializing all the Q-Values to zero for each state-action pair."""
    
    action_space_size = env.action_space.n
    state_space_size = env.observation_space …
    more ...

    Algorithms

    Linked List

    206. Reverse Linked List

    class ListNode:
        def __init__(self, val):
            self.val = val
            self.next = None
    
    class Solution:
        def reverseLinkedList(self, head: ListNode) -> ListNode:
            if not head or not head.next:
                return head
            pre, cur, post = None, head, head.next
            while cur:
                post = cur.next
                cur.next = pre …
    more ...

    【RL】User Simulator

    User Simulator BackGround

    为什么需要用户模拟器?

    监督学习方法缺陷:

    1. 需要收集大量实际的人机与人人的训练标注数据,昂贵且耗时。

    2. 此外,即 …

    more ...