{"id":16590250,"url":"https://github.com/abaofromcug/data-structure","last_synced_at":"2025-10-12T12:03:45.850Z","repository":{"id":184182768,"uuid":"103095368","full_name":"AbaoFromCUG/Data-Structure","owner":"AbaoFromCUG","description":"数据结构各种大小作业","archived":false,"fork":false,"pushed_at":"2018-01-03T15:06:20.000Z","size":31345,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-12T05:53:15.630Z","etag":null,"topics":["cpp","fucking","qml"],"latest_commit_sha":null,"homepage":null,"language":"QML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AbaoFromCUG.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-09-11T05:55:55.000Z","updated_at":"2024-11-06T14:32:42.000Z","dependencies_parsed_at":"2023-07-27T11:49:32.107Z","dependency_job_id":null,"html_url":"https://github.com/AbaoFromCUG/Data-Structure","commit_stats":null,"previous_names":["abaofromcug/data-structure"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/AbaoFromCUG/Data-Structure","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AbaoFromCUG%2FData-Structure","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AbaoFromCUG%2FData-Structure/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AbaoFromCUG%2FData-Structure/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AbaoFromCUG%2FData-Structure/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AbaoFromCUG","download_url":"https://codeload.github.com/AbaoFromCUG/Data-Structure/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AbaoFromCUG%2FData-Structure/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279011278,"owners_count":26084928,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","fucking","qml"],"created_at":"2024-10-11T23:11:54.462Z","updated_at":"2025-10-12T12:03:45.810Z","avatar_url":"https://github.com/AbaoFromCUG.png","language":"QML","readme":"# 数据结构的各种实习\n\n\u003c!-- TOC depthFrom:1 depthTo:6 withLinks:1 updateOnSave:1 orderedList:0 --\u003e\n\n- [数据结构的各种实习](#数据结构的各种实习)\n\t\t- [作业p84 2.6](#作业p84-26)\n\t\t- [作业p86 2.15](#作业p86-215)\n\t- [实习一](#实习一)\n\t\t- [关于法雷序列](#关于法雷序列)\n\t\t\t- [方案一：递归](#方案一递归)\n\t\t\t\t- [深度优先](#深度优先)\n\t\t\t\t- [广度优先](#广度优先)\n\t\t\t- [方案二： 循环](#方案二-循环)\n\t\t- [关于大数阶乘](#关于大数阶乘)\n\t- [实习二](#实习二)\n\t\t- [实现一个计算器](#实现一个计算器)\n\t\t- [关于火车转运问题](#关于火车转运问题)\n\n\u003c!-- /TOC --\u003e\n\n\n\n\n### 作业p84 2.6\n实现了一个顺序表，一些基本功能，模板的\n\n### 作业p86 2.15\n\n* 类LinkedList\n```cpp\nstruct Item{\n    int date;\n    Item* linked;\n}\n```\n节点的单向链表\n功能简单，归并，全部排序，增删该查\n\n\n* 类SuperList，实现了实习一的关于链表的一些要求\n\n```cpp\ntemplate\u003ctypename T\u003e\nstruct ListNode {\n\tT date;\n\tListNode* link;\n    ....\n};\n```\n各全模板，可自定义排序，通过传递函数指针\n重载了排序函数 begin ,end, sortFun*;\n\n##  实习一\n\n### 关于法雷序列\n\n#### 方案一：递归\n\n##### 深度优先\n在我的电脑上，大概3950-4000 之间的时候就开始栈溢出\n```cpp\nvoid FareyList::recursion(ListNode\u003cFraction\u003e* a, ListNode\u003cFraction\u003e* b)\n{\n\tif ((a-\u003edate.d + b-\u003edate.d)\u003e maxNum)\n\t\treturn;\n\tListNode\u003cFraction\u003e *m = list.insertBetween(a, b, Fraction{ a-\u003edate.n + b-\u003edate.n,a-\u003edate.d + b-\u003edate.d });\n\trecursion(a, a-\u003elink);\n\trecursion(m, b);\n}\n```\n\u003cimg src=\"assets/markdown-img-paste-20170916120930883.png\" width=500 alt=\"正常的运行\" \u003e\n-----\n\u003cimg src=\"assets/markdown-img-paste-2017091612064045.png\" width=500 alt=\"Stack overflow\"\u003e\n\n##### 广度优先\n```cpp\nvoid FareyList::recursion()\n{\n\tListNode\u003cFraction\u003e* a = list.getFirst();\n\tListNode\u003cFraction\u003e* b = list.getFirst()-\u003elink;\n\twhile (b)\n\t{\n\t\tif ((a-\u003edate.d + b-\u003edate.d) \u003c= maxNum) {\n\t\t\tlist.insertBetween(a, b, Fraction{ a-\u003edate.n + b-\u003edate.n,a-\u003edate.d + b-\u003edate.d });\n\t\t\tover = false;\n\t\t}\n\t\ta = b;\n\t\tb = b-\u003elink;\n\t}\n\tif (!over) {\n\t\tover = true;\n\t\trecursion();\n\t}\n}\n```\n\n\u003cimg src=\"assets/markdown-img-paste-20170916134915584.png\" width=500 alt=\"深度优先vs广度优先\"\u003e\n\n但是仍然崩溃，此时size=10938995\n\n\u003cimg src=\"assets/markdown-img-paste-2017091614375667.png\" width=500 alt=\"广度优先\"\u003e\n\n\u003e 总结： 法雷序列如果通过递归来进行搜索（？），那么无论是深度优先还是广度优先，选好终结条件是关键，另外，感觉深度优先递归（2的n次方？）的话更容易溢出，而广度优先由于递归的层数更少（递归层数？），更不容易溢出?但是，最终仍然会因为new的空间太大而不可以继续new\n\n\n#### 方案二： 循环\n--------\n\u003e17.9.22更新\n\n迭代计算法：参考了acm相关论文的一种方法\n\n\u003e 法雷序列有个比较明显，基本上也是众所周知的性质，对于法雷序列中的任意三个连续的分数，设为p1/q1, p2/q2, p3/q3, 应该有性质:p2/q2 = (p1+p3)/(q1+q2)，其中p2,q2可能是经过约分得到的。如此我们希望通过已知的前两个数，直接能得到第三个数，然后依次类推，推出所有的数。  实际上也是可以的，虽然从表面上看，知道p1,q1,p2,q2之后,p3,q3有多种情况，如(p2-p1)/(q2-q1), (p2*2-p1)/(q2*2-q1)…但是我们只需选择最小的一个，容易证明最小的p3/q3应该为(p2*x-p1)/(q2*x-q1)，其中x=max{k∣q2*k-q1≤n}，这点容易证明。\n\n如上所描述，本种方法直接利用了这个的结论*最小的p3/q3应该为(p2*x-p1)/(q2*x-q1)，其中x=max{k∣q2*k-q1≤n}*\n于是我们主要的计算就是来算x，即k的最大值，通过演算，k≤(n+q1)/q2，利用计算机除法整除的性质，可以快速算出k\n```cpp\nlist.makeEmpty();\nlist \u003c\u003c Fraction{ 0,1 } \u003c\u003c Fraction{ 1,maxNum };\nListNode\u003cFraction\u003e* a, *b;\na = list.getFirst();\nb = a-\u003elink;\ntry{\n\t\twhile (b-\u003edate.d != 1) {\n\t\t\t\tint x = (a-\u003edate.d + num) / b-\u003edate.d;\t//整除的特性\n\t\t\t\tlist.append(Fraction{ b-\u003edate.n*x - a-\u003edate.n,b-\u003edate.d*x - a-\u003edate.d });\n\t\t\t\ta = b;\n\t\t\t\tb = b-\u003elink;\n\t\t}\n}catch(...){\n\t\temit error(0);\n}\n```\n\n\n### 关于大数阶乘\n\n高位计算到低位\n低位循环进位到高位\n3个循环，2个移动节点\n```cpp\nfor (int i = 2; i \u003c= maxNum; i++)\n{\n\t\tDListNode\u003cint\u003e* node=list.getLast();       //用来计算的node\n\t\tDListNode\u003cint\u003e* mNode;      //用来进位的node\n\t\twhile (node!=list.getFirst()-\u003eLLink) {\n\t\t\t\t long long n= node-\u003edate*i;\n\t\t\t\t node-\u003edate=n%storeLong;\n\t\t\t\t n=n/storeLong;\n\t\t\t\t //如果需要进位的数非零的话\n\t\t\t\t mNode=node-\u003eRLink;\n\t\t\t\t //循环进位\n\t\t\t\t while (n) {\n\t\t\t\t\t\t if(!mNode){\n\t\t\t\t\t\t\t\t list.append(0);\n\t\t\t\t\t\t\t\t mNode = list.getLast();\n\t\t\t\t\t\t\t\t mNode-\u003edate = n%storeLong;\n\t\t\t\t\t\t\t\t n /= storeLong;\n\t\t\t\t\t\t }else {\n\t\t\t\t\t\t\t\tn=mNode-\u003edate+n;\n\t\t\t\t\t\t\t\tmNode-\u003edate=n%storeLong;\n\t\t\t\t\t\t\t\tn=n/storeLong;\n\t\t\t\t\t\t }\n\t\t\t\t\t\t mNode=mNode-\u003eRLink;\n\t\t\t\t }\n\t\t\t\t node = node-\u003eLLink;\n\t\t}\n}\n```\n\n\n最后再上两个效果图片\n\n![](assets/markdown-img-paste-20170922141136399.png)\n\n![](assets/markdown-img-paste-20170922141241239.png)\n\n\n##  实习二\n\n\n### 实现一个计算器\n\n关于运算符的优先级别\n\u003e r：代表根号，如2r4就是代表，求4的二次方根\u003cbr\u003e\n\u003e e:科学记数法\u003cbr\u003e\n\u003e s，t,c:代表sin tan cos\n\n* 1 表示当前运算符大于小于栈顶的运算符号,栈顶符号出栈参与运算,然后在加当前符号push\n* 2 表示当前运算符号大于栈顶的运算符号,直接push\n* 3 表示当前符号是\")\",需要运算,直到最后将对应的\"(\" 出栈完毕\n* 4 表示当前符号是\"#\" 需要将所有的有效运算符号依次出栈参与运算\n* 5 表示遇到非法的符号结对,比如当前是(, 而栈顶是#\n* 横向数据是当前扫描的字符，纵向是符号栈顶的数据\n\n| | + -| * / |e^r% |  s t c  | ( |  ) | # |\n|:----:| :----- | :------- | :------- |:---| :----- |  :------- |:---|\n|+ -|1|2|2|2|2|3|4|\n|* /|1|1|2|2|2|3|4|\n|e^r%|1|1|1|2|2|3|4|\n|s t c|1|1|1|1|2|3|4|\n| (|2|2|2|2|2|3|5|\n| )|5|5|5|5|5|5|5|\n|#|2|2|2|2|2|5|4|\n\n两个栈|一个数字栈，一个符号栈\n这样可以不用将中缀表达式转为后缀表达式\n![样例图片](assets/markdown-img-paste-2017100922284051.png)\n\n### 关于火车转运问题\n\n```cpp\nvoid Manager::startRun(int *num, int length)\n{\n\tthis-\u003einitData();  //将waitNum设置为1\n\tfor (int i = 0; i \u003c length; i++)\n\t{\n\t\t//如果是我们要等的数字的话\n\t\tif (num[i]==waitNum)\n\t\t{\n\t\t\tif (haveEmpty()){\n\n\t\t\t\t//如果有空轨道\n\t\t\t\tcout \u003c\u003c\"                     --------\u003e数字\"\u003c\u003cwaitNum\u003c\u003c\"从\"\u003c\u003c getEmptyTrack()\u003c\u003c\"号轨道路过并出\"  \u003c\u003c endl;\n\t\t\t\twaitNum++;\n\t\t\t}\n\t\t\telse\n\t\t\t\t//如果没有空轨道了，就是没有办法转运\n\t\t\t\tcout \u003c\u003c \"无法转运\" \u003c\u003c endl;\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\t//不是，那么就要等待,放到尾部最小的一个对列\n\t\t\tint tempNum = -1;\n\t\t\tMyQueue\u003cint\u003e* p = getMaxRTrack(num[i], tempNum);\n\t\t\tif (!p) {\n\t\t\t\tcout \u003c\u003c \"无法转运\" \u003c\u003c endl;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tcout \u003c\u003c \"数字\" \u003c\u003c num[i] \u003c\u003c \"在\" \u003c\u003c tempNum \u003c\u003c \"号铁轨入轨\" \u003c\u003c endl;\n\t\t\t\tp-\u003einQueue(num[i]);\n\t\t\t}\n\t\t}\n\t\toutTrain();\n\t}\n}\n```\n\n\n```\n\n这是一种相对来说比较优的解：\n一个一个数字进行比较：\n如果是我们要等的数据：{\n    如果有空的队列则可以直接输出，\n    否则就要入队：\n      如果能找到末尾最大，且末尾数据小于当前数字，则进入这个最优的队列\n      如果没有找到最优的队列，则找到一个空的队列，进队列\n      如果所有的队列都有数字，且当前数字不能进入任意一个队列，那么就不能转运\n}\n每比较一个数字，调用一个outTrain();函数将能出的数据出掉\n\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabaofromcug%2Fdata-structure","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabaofromcug%2Fdata-structure","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabaofromcug%2Fdata-structure/lists"}