{"id":17011819,"url":"https://github.com/flaribbit/data-structure-review-reference","last_synced_at":"2025-03-22T13:23:46.206Z","repository":{"id":137699174,"uuid":"208440965","full_name":"flaribbit/Data-structure-review-reference","owner":"flaribbit","description":"Data structure final exam review reference, just backup~","archived":false,"fork":false,"pushed_at":"2022-01-12T15:11:47.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-27T12:49:34.550Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","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/flaribbit.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-14T13:00:40.000Z","updated_at":"2022-01-01T16:33:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"d8e8c78b-d70e-4e59-bb43-073d9f7c2e33","html_url":"https://github.com/flaribbit/Data-structure-review-reference","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flaribbit%2FData-structure-review-reference","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flaribbit%2FData-structure-review-reference/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flaribbit%2FData-structure-review-reference/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flaribbit%2FData-structure-review-reference/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flaribbit","download_url":"https://codeload.github.com/flaribbit/Data-structure-review-reference/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244960769,"owners_count":20538880,"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","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":[],"created_at":"2024-10-14T06:08:08.203Z","updated_at":"2025-03-22T13:23:46.198Z","avatar_url":"https://github.com/flaribbit.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"## 实验复习(本周五前，1班上传1，2，3题完整答案；2班上传4，5，6完整答案。具体任务由班长安排)\n\n执行 `make all \u0026\u0026 rev1 \u0026\u0026 rev2 \u0026\u0026 rev3` 编译所有程序并运行\n\n对于程序2，测试的输入数据为 `ab..cd...` ，其他程序自带了测试数据\n\n### 1.  设单链表中有仅三类字符的数据元素(大写字母、数字和其它字符)，要求利用原单链表中结点空间设计出三个单链表的算法，使每个单链表只包含同类字符。\n```C\ntypedef char datatype;\ntypedef struct node {datatype data; struct node *next;}lklist;\nvoid split(lklist *head,lklist *\u0026ha,lklist *\u0026hb,lklist *\u0026hc)\n{\n   lklist *p; ha=0,hb=0,hc=0;\n   for(p=head;p!=0;p=head)\n   {\n    head=p-\u003enext; p-\u003enext=0;\n    if (p-\u003edata\u003e='A' \u0026\u0026 p-\u003edata\u003c='Z') {p-\u003enext=ha; ha=p;}\n    else if (p-\u003edata\u003e='0' \u0026\u0026 p-\u003edata\u003c='9') {p-\u003enext=hb; hb=p;} else {p-\u003enext=hc; hc=p;}\n   }\n}\n```\n\n### 2. 设计在链式存储结构上交换二叉树中所有结点左右子树的算法。\n```C\ntypedef struct node {int data; struct node *lchild,*rchild;} bitree;\nvoid swapbitree(bitree *bt)\n{\n   bitree *p;\n   if(bt==0) return;\nswapbitree(bt-\u003elchild); swapbitree(bt-\u003erchild);\np=bt-\u003elchild; bt-\u003elchild=bt-\u003erchild; bt-\u003erchild=p;\n}\n```\n\n### 3. 设计两个有序单链表的合并排序算法。\n```C\nvoid mergelklist(lklist *ha,lklist *hb,lklist *\u0026hc)\n{\n   lklist *s=hc=0;\n   while(ha!=0 \u0026\u0026 hb!=0)\n     if(ha-\u003edata\u003chb-\u003edata){if(s==0) hc=s=ha; else {s-\u003enext=ha; s=ha;};ha=ha-\u003enext;}\n     else {if(s==0) hc=s=hb; else {s-\u003enext=hb; s=hb;};hb=hb-\u003enext;}\n   if(ha==0) s-\u003enext=hb; else s-\u003enext=ha;\n}\n```\n\n### 4. 设计一个求结点x在二叉树中的双亲结点算法。\n```C\ntypedef struct node {datatype data; struct node *lchild,*rchild;} bitree;\nbitree *q[20]; int r=0,f=0,flag=0;\nvoid preorder(bitree *bt, char x)\n{\n  if (bt!=0 \u0026\u0026 flag==0)\nif (bt-\u003edata==x) { flag=1; return;}\nelse {r=(r+1)% 20; q[r]=bt; preorder(bt-\u003elchild,x); preorder(bt-\u003erchild,x); }\n}\nvoid parent(bitree *bt,char x)\n{\n   int i;\n   preorder(bt,x);\n   for(i=f+1; i\u003c=r; i++) if (q[i]-\u003elchild-\u003edata==x || q[i]-\u003erchild-\u003edata) break;\n   if (flag==0) printf(\"not found x\\n\");\n   else if (i\u003c=r) printf(\"%c\",bt-\u003edata); else printf(\"not parent\");\n}\n```\n\n### 5. 设计在顺序有序表中实现二分查找的算法。\n```C\nstruct record {int key; int others;};\nint bisearch(struct record r[ ], int k)\n{\n  int low=0,mid,high=n-1;\n  while(low\u003c=high)\n{\n    mid=(low+high)/2;\n    if(r[mid].key==k) return(mid+1); else if(r[mid].key\u003ek) high=mid-1; else low=mid+1;\n  }\n  return(0);\n}\n```\n\n### 6. 设计在链式结构上实现简单选择排序算法。\n```C\nvoid simpleselectsorlklist(lklist *\u0026head)\n{\n  lklist *p,*q,*s;  int min,t;\n  if(head==0 ||head-\u003enext==0) return;\n  for(q=head; q!=0;q=q-\u003enext)\n  {\n    min=q-\u003edata; s=q;\n    for(p=q-\u003enext; p!=0;p=p-\u003enext) if(min\u003ep-\u003edata){min=p-\u003edata; s=p;}\n    if(s!=q){t=s-\u003edata; s-\u003edata=q-\u003edata; q-\u003edata=t;}\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflaribbit%2Fdata-structure-review-reference","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflaribbit%2Fdata-structure-review-reference","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflaribbit%2Fdata-structure-review-reference/lists"}