From d75a19baab737631a5bd1816c1cecdd6308c6e43 Mon Sep 17 00:00:00 2001 From: Han Jiang Date: Mon, 19 Jun 2017 21:42:09 +0800 Subject: [PATCH] hx --- 2017-1/hx/.DS_Store | Bin 0 -> 14340 bytes 2017-1/hx/._.DS_Store | Bin 0 -> 4096 bytes .../._Header.h" | Bin 0 -> 4096 bytes .../._test.c" | Bin 0 -> 4096 bytes ...344\270\212\347\256\227\346\263\2252.12.c" | Bin 0 -> 4096 bytes .../Header.h" | 19 ++ .../test.c" | 13 + ...344\270\212\347\256\227\346\263\2252.12.c" | 115 ++++++++ ...6\347\232\204\351\201\215\345\216\206.cpp" | Bin 0 -> 4096 bytes ...6\347\232\204\351\201\215\345\216\206.cpp" | 225 ++++++++++++++++ ...215\347\232\204\346\243\200\351\252\214.c" | Bin 0 -> 4096 bytes ...260\345\210\266\350\275\254\346\215\242.c" | Bin 0 -> 4096 bytes .../._\350\241\214\347\274\226\350\276\221.c" | Bin 0 -> 4096 bytes ...215\347\232\204\346\243\200\351\252\214.c" | 113 ++++++++ ...260\345\210\266\350\275\254\346\215\242.c" | 112 ++++++++ .../\350\241\214\347\274\226\350\276\221.c" | 105 ++++++++ ...277\346\200\247\351\223\276\350\241\250.c" | Bin 0 -> 4096 bytes ...277\346\200\247\351\223\276\350\241\250.c" | 91 +++++++ ...221\347\232\204\351\201\215\345\216\206.c" | Bin 0 -> 4096 bytes ...221\347\232\204\351\201\215\345\216\206.c" | 90 +++++++ .../.DS_Store" | Bin 0 -> 6148 bytes .../._.DS_Store" | Bin 0 -> 4096 bytes ...1\346\216\222\345\272\217\346\240\221.cpp" | Bin 0 -> 4096 bytes ...1\346\216\222\345\272\217\346\240\221.cpp" | 159 +++++++++++ ...246\344\270\216\345\256\275\345\272\246.c" | Bin 0 -> 4096 bytes ...246\344\270\216\345\256\275\345\272\246.c" | 115 ++++++++ ...2\346\234\254\346\223\215\344\275\234.cpp" | Bin 0 -> 4096 bytes ...6\345\274\217\346\261\202\345\200\274.cpp" | Bin 0 -> 4096 bytes ...2\346\234\254\346\223\215\344\275\234.cpp" | 248 ++++++++++++++++++ ...6\345\274\217\346\261\202\345\200\274.cpp" | 193 ++++++++++++++ 30 files changed, 1598 insertions(+) create mode 100644 2017-1/hx/.DS_Store create mode 100644 2017-1/hx/._.DS_Store create mode 100644 "2017-1/hx/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/._Header.h" create mode 100644 "2017-1/hx/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/._test.c" create mode 100644 "2017-1/hx/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/._\344\271\246\344\270\212\347\256\227\346\263\2252.12.c" create mode 100644 "2017-1/hx/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/Header.h" create mode 100644 "2017-1/hx/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/test.c" create mode 100644 "2017-1/hx/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\344\271\246\344\270\212\347\256\227\346\263\2252.12.c" create mode 100644 "2017-1/hx/\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/._\345\233\276\347\232\204\351\201\215\345\216\206.cpp" create mode 100644 "2017-1/hx/\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/\345\233\276\347\232\204\351\201\215\345\216\206.cpp" create mode 100644 "2017-1/hx/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/._\346\213\254\345\217\267\345\214\271\351\205\215\347\232\204\346\243\200\351\252\214.c" create mode 100644 "2017-1/hx/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/._\346\225\260\345\210\266\350\275\254\346\215\242.c" create mode 100644 "2017-1/hx/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/._\350\241\214\347\274\226\350\276\221.c" create mode 100644 "2017-1/hx/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\346\213\254\345\217\267\345\214\271\351\205\215\347\232\204\346\243\200\351\252\214.c" create mode 100644 "2017-1/hx/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\346\225\260\345\210\266\350\275\254\346\215\242.c" create mode 100644 "2017-1/hx/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\350\241\214\347\274\226\350\276\221.c" create mode 100644 "2017-1/hx/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/._\346\213\206\345\210\206\347\272\277\346\200\247\351\223\276\350\241\250.c" create mode 100644 "2017-1/hx/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/\346\213\206\345\210\206\347\272\277\346\200\247\351\223\276\350\241\250.c" create mode 100644 "2017-1/hx/\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/._\344\272\214\345\217\211\346\240\221\347\232\204\351\201\215\345\216\206.c" create mode 100644 "2017-1/hx/\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/\344\272\214\345\217\211\346\240\221\347\232\204\351\201\215\345\216\206.c" create mode 100644 "2017-1/hx/\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/.DS_Store" create mode 100644 "2017-1/hx/\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/._.DS_Store" create mode 100644 "2017-1/hx/\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/._\344\272\214\345\217\211\346\216\222\345\272\217\346\240\221.cpp" create mode 100644 "2017-1/hx/\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/\344\272\214\345\217\211\346\216\222\345\272\217\346\240\221.cpp" create mode 100644 "2017-1/hx/\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/._\350\256\241\347\256\227\344\272\214\345\217\211\346\240\221\351\253\230\345\272\246\344\270\216\345\256\275\345\272\246.c" create mode 100644 "2017-1/hx/\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\350\256\241\347\256\227\344\272\214\345\217\211\346\240\221\351\253\230\345\272\246\344\270\216\345\256\275\345\272\246.c" create mode 100644 "2017-1/hx/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/._\345\215\225\345\220\221\351\230\237\345\210\227\345\237\272\346\234\254\346\223\215\344\275\234.cpp" create mode 100644 "2017-1/hx/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/._\345\221\275\344\273\244\350\241\214\345\256\236\347\216\260\350\241\250\350\276\276\345\274\217\346\261\202\345\200\274.cpp" create mode 100644 "2017-1/hx/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/\345\215\225\345\220\221\351\230\237\345\210\227\345\237\272\346\234\254\346\223\215\344\275\234.cpp" create mode 100644 "2017-1/hx/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/\345\221\275\344\273\244\350\241\214\345\256\236\347\216\260\350\241\250\350\276\276\345\274\217\346\261\202\345\200\274.cpp" diff --git a/2017-1/hx/.DS_Store b/2017-1/hx/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..08d91e798f94530b3a2cc2f4446c42d4c205ae5d GIT binary patch literal 14340 zcmeHOUu+ab7@x0y=--Mdms zO$~}K1l0HfYD|m|8hA266XS#Wpcs6Rgs5QRgTDA^G@AIN-|Xxj*K7O03!2MJGV{&M zH?w=c-~4WOzr8s^2(+j5MnYnQ5D7E0v>b~IghZLmNzBjkoK%cGfVmno)+sr)x_kIg zO{OPhTh5%(b32N#i_I^=TsqZoNY0&apJZOwi^aZ&qT-U$MP-sKOY#!wSkI_4(c__4 zB*B1SKrkQ}5DW+g9-IMo@5Ll7=2nz~0l|P^Aj<%|K14Ay8xQOZxBjIA3-$=l{Ol3l zPgtj{f;Jl1cwlF^MGq$6Q_=FN5QG@Or(=IK7#9!h47Yqb0sqW+oZ!q5L@3~&9s8sH zZ~}2|MJX5%49sPK#riDvzQ|+m#DqJZu$%<;ew`S%%!T7`%}cxOTI#4DjhniW2yV(!vm(RI}`0r+SXnFIEOWF6zBSZ{s>(@HPyVmwISNn z*fiY`ooZ=`HAJ^HHBV1V(z5!-wyqOnlV_*SO}}u3qk`bdKq~T3UY!lmax)zqV$tg% z#2>P+7?j28zOMbs2(8NCC+{BjOviTnjg*UagjTrt?x8E`*oRXF^A98)D?MhrBeXK9 zS;@4edB$$b>M_q6?x1I!@mTGM>!iF6f8d~rb6MXArD@lA&cF#~#^}UpE(Q5o`O?Um z$2Z2d?|iD`&XPwes8Xd=4`fW&Ojt(WgsFR@LzbAZs4EwmCDA%*Fr6?@r%i8?pQBb?Ez=v)u#TVN8AoSF)P0XytJX`>QP$s) zGO*;`$~tv}Of{+3MIihTo0Kgwb>-euxT1XOR%M$+b-B;d5{AXQT9j6a9*_qzoK4vJty(t}MCqAgTUiY|Rr01m<-=!RZ62FKw9XmAq7;WW75!8v#t zF2F1BDqMl9@D{uc*Wm_y1Rula@CDq0Z{aTgctxRB5At?c!ac0zd>v7%!Pl{9Xg;k* zI`{1TkFe1?@tLoNm+S;-!o?XVgmCIF-FB+~2UoD{;{Nz zLs1!L^5q{2oR%^1OH3VVZ8Q?0Ogg-|wjP^BC~e+czagT~Vid0I58k{*iO^EiDEBsP zQxsZ)BIe#5t>|5Za^>E(73d{_Pp*$BlKkM(dzV}zpO7z6bhpWO>E;UyH|CAf?td<{kT4!oZyxqYG7xP=d9OOC(2^6!Cv{(_-#xuP`_+;FS*{ z=E=SgpK}E!!GK^uFd!JX&p;`!#@PP9Jqz#uzdu3L1OtMBf@1(mI(s_X5mvY>As->z zYZt|Q0y7))8D^HS?oYvj4Pgy`J03RJcDx;|FHGo*vpU)tZn1{xp>G5fzyJHZheh`H Ue-ZzOe_hLs0>eM06$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIk*Y|peR=07!nd> zJ?rFuhz^DdtcpejM?+vV1V%$(Gz3ONU^E0qLtr!nMnhmU1V%$(Gz3ONfXX4j2s96b z!9Xq~BePhcD784hv?w`MAuYcsTOl*ABsH%jGe0jeC#O;&CpE1^At@&@FB{m^h3Xp8 P6srH>UXfvt`~M#R%-A0@ literal 0 HcmV?d00001 diff --git "a/2017-1/hx/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/._Header.h" "b/2017-1/hx/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/._Header.h" new file mode 100644 index 0000000000000000000000000000000000000000..34be0085f3811c22b2ef57b1928118605df7aa67 GIT binary patch literal 4096 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^1EBI0G%X<0LE_vD4C2Z8xq68O1v#mDA*mH5u6fD%DVcfc5Dl+^R3rm~IYLct zYDr>BVo9P^wy%p%Vp3{Od|F~=PL^3-Nv>I8Vn#_`x`}aeW?qp=u4y7rb8aG#Q<7ht zVQuh<_sVI<&pp#;d^Y41k>;7bv;SYvn}D)w=S6LjW_HDnYk&Ofd_HTzloe)z{=A)*yEZpiK%6>Cj)uT! z2#kinXb6mkz-S1JhQMeDjE2By2#kinXb22+2rvR20K#A(7m|@#tWcC%oL^d$oT`wP xUzDu?>>;M+m1O4UCFbN*D&(Z5l_(_TB<5uU`@&FNLz+VMKin%a408Yf0{{({ZbSe8 literal 0 HcmV?d00001 diff --git "a/2017-1/hx/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/._test.c" "b/2017-1/hx/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/._test.c" new file mode 100644 index 0000000000000000000000000000000000000000..19714cf5f3ca9d024ddab02044e75eedafd54315 GIT binary patch literal 4096 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^1EBH@G%X<0LE`)j4C2Z8xq68O1v#mDA*mH5u6fD%DVcfc5Do8vR3rm~IYLct zYDr>BVo9P^wy%p%Vp3{Od|F~=PL^3-Nv>I8Vn#_`x`}aeW?qp=u4y7rb7@JMu7$Os zv5AqPxuu24rVLRbWEkZB{|5j$ CRc!zO literal 0 HcmV?d00001 diff --git "a/2017-1/hx/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/._\344\271\246\344\270\212\347\256\227\346\263\2252.12.c" "b/2017-1/hx/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/._\344\271\246\344\270\212\347\256\227\346\263\2252.12.c" new file mode 100644 index 0000000000000000000000000000000000000000..c351e05814700cc7b4ad5bb75fd83485c1cde744 GIT binary patch literal 4096 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^1EBI7Xj(v~gT(n67{rtFbM+Dn3UX5QLQ*SAT=SCiQ!?|?AsXHTsgn#0<_I;p zsU?Xii6x0v*}g75iAkwB@o9;fIay|TCAnsWi5Vq%=_ba>nR!Jfxu%Ig&7~!2x)#=k z#wJFF=9U&FpIFlaSE^S2oyou`urjhjom=3>!|gmf4C42yYOLpAD6GCT!|dA1RLOO- z1!KN0JaXgA+s54a4#r6z+Nx9cnPmR5_&j$JqtdKop)ld!i>((;wD_CtbnLXu1h0IN zOV1}O+~@t$`(^Jo@7~d|LyHd5gRnh4lUDtC6`v!W_c|&XwRjS z#ilj)+J=w`qSlc`&j3r{lTSc|W%A zQhfaMj8Uv*zlr+aG)VA_lA|Fo8UmvsFd71*Aut*OqaiRF0;3@?8UmvsFd72LA;1Xa zfG`-yg=AzFD-@*`=a&{Grz)i77iBAC=9Q%8m1O4UCFbN*D&(Z5l_(_TB<5uU`@&FN RLz+VMKin%a408Yf0{}xwsyqMy literal 0 HcmV?d00001 diff --git "a/2017-1/hx/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/Header.h" "b/2017-1/hx/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/Header.h" new file mode 100644 index 00000000..2c7298be --- /dev/null +++ "b/2017-1/hx/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/Header.h" @@ -0,0 +1,19 @@ +#include +#include + +#define OK 0 +#define ERROR 1 +#define OVERFLOW 2 + +typedef int Elemtype; + +typedef struct LNode{ + int data; + struct LNode *next; +}LNode,*LinkList; + +void CreateList(LinkList* ,int ); +void SortList(LinkList,int); +void Traverse(LinkList ); +void MergeList_L(LinkList ,LinkList ,LinkList *); +void ShowList(LinkList *,LinkList *); diff --git "a/2017-1/hx/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/test.c" "b/2017-1/hx/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/test.c" new file mode 100644 index 00000000..abef81f3 --- /dev/null +++ "b/2017-1/hx/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/test.c" @@ -0,0 +1,13 @@ +#include +#include"Header.h" +#include + +int main() +{ + int i,j; + LinkList L1,L2; + ShowList (&L1,&L2); + return OK; + +} + diff --git "a/2017-1/hx/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\344\271\246\344\270\212\347\256\227\346\263\2252.12.c" "b/2017-1/hx/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\344\271\246\344\270\212\347\256\227\346\263\2252.12.c" new file mode 100644 index 00000000..8da15268 --- /dev/null +++ "b/2017-1/hx/\347\254\254\344\270\200\346\254\241\344\275\234\344\270\232/\344\271\246\344\270\212\347\256\227\346\263\2252.12.c" @@ -0,0 +1,115 @@ +#include +#include"Header.h" +#include +//建立线性表并将其置空 +void CreateList(LinkList *L,int n) +{ + LinkList p = NULL; + int i ; + *L = (LinkList)malloc(sizeof(LNode)); + (*L)->next = NULL; + srand((unsigned)time( NULL ) ); + for(i=0;idata);// + p->data = rand()%1024; + p->next = (*L)->next; + (*L)->next = p; + } +}//createlist +void SortList(LinkList L,int n) +{ + int i=0; + int j=0; + LinkList head; + LinkList p1; + LinkList p2; + + for(i=0;inext; + for( j=0;jnext; + if( p1->data > p2->data){ + Elemtype temp = p1->data; + p1->data = p2 -> data; + p2->data = temp; + } + head = head->next; + } + } +} + +void Traverse(LinkList L) +{ + LNode *p = L->next; + while(p){ + printf("%d ",p->data); + p = p->next; + } +} + +void MergeList_L(LinkList La,LinkList Lb,LinkList *Lc) +{ + LinkList pa,pb,pc; + pa = La->next; + pb = Lb->next; + *Lc = pc = La; + while(pa&&pb){ + if(pa->data <= pb->data){ + pc->next = pa; + pc = pa; + pa = pa->next; + } + else{ + pc->next = pb; + pc = pb; + pb =pb ->next; + } + } + pc->next = pa? pa:pb; + free(Lb); +} + +void ShowList(LinkList *L1,LinkList *L2) +{ + int i,j; + LinkList Lc; + *L1 =(LinkList) malloc(sizeof(LNode)); + *L2 =(LinkList) malloc(sizeof(LNode)); + + printf("L1的长度为:"); + scanf("%d",&i); + + CreateList(L1,i); + printf("获取L1中的数据:\n"); + Traverse(*L1); + printf("\n"); + + SortList(*L1,i); + printf("将L1中的数据由小到大排列:\n"); + Traverse(*L1); + printf("\n"); + + printf("\nL2的长度为:"); + scanf("%d",&j); + + CreateList(L2,j); + printf("\n获取L2中的数据:"); + Traverse(*L2); + printf("\n"); + + SortList(*L2,j); + printf("将L2中的数据由小到大排列:\n"); + Traverse(*L2); + printf("\n"); + + printf("将所有数据由小到大排列:\n"); + MergeList_L(*L1,*L2,&Lc); + Traverse(Lc); +} + + + diff --git "a/2017-1/hx/\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/._\345\233\276\347\232\204\351\201\215\345\216\206.cpp" "b/2017-1/hx/\347\254\254\344\270\203\346\254\241\344\275\234\344\270\232/._\345\233\276\347\232\204\351\201\215\345\216\206.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..eeeca5e97067b73790d3ba6a0862c517c2d66d00 GIT binary patch literal 4096 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^1EBI5Xj(v~gT(n67{rtFbM+Dn3UX5QLQ*SAT=SCiQ!?|?AsXHTsZIt4bA+1Q z)RM%M#F9j-Y+o0j#H7@m__V~#oGi1vl3cUG#Eg=>bQ9y`%)BC#T+>9L=F*ZhT?=bN zV-q7ob4v@8Pn);P9i6u;UNT_rroWv9bEYgi7I>sNZOO9Jx12uiZIy0dQ=i(!yEaQY z@~eEqinIUN3ccQ&znb9H`^G=*3is(;y|iWWR!d!Heaq0dtTO)cHRhD)G9`Yet;!qA zl`no&Ijy*I`%24>n@ +#include +#define MAX_VEX 20 +#define Queue_Size 100 +int visited[MAX_VEX]; +typedef int ElemType; +typedef int VerType; +typedef enum{ + OK, + ERROR, + OVERFLOW +}Status; + +typedef struct q_node{ + ElemType data; + struct q_node *previous; + struct q_node *next; +}Qnode,*Pq_node; + +typedef struct link_queue{ + Pq_node front; + Pq_node rear; +}LinkQueue; + +typedef struct ArcCell{ + ElemType eadj; +}AdjMatrix[MAX_VEX][MAX_VEX]; + +typedef struct graph{ + AdjMatrix arcs; + int arcs_num; + int vers_num; +}Graph; + + +Status InitQueue(LinkQueue *q); +Status EnQueue(LinkQueue*q, ElemType e); +Status DeQueue(LinkQueue*q,ElemType *e); +bool EmptyQueue(LinkQueue q); + + +Status Add(Graph*g,int i,int j); +Status CreatGraph(Graph*g); +VerType ToFirstAdjVex(Graph g,int num); +VerType ToNextAdjVex(Graph g,int i,int j); +void BFSTraverse(Graph g,int a,int b); +Status PrintFoot(LinkQueue q,VerType start); + + + +Status InitQueue(LinkQueue *q){ + q->front=(Pq_node)malloc(Queue_Size*sizeof(Qnode)); + q->rear=(Pq_node)malloc(Queue_Size*sizeof(Qnode)); + q->front=q->rear; + if(!(q->front)){ + return ERROR; + } + q->front->next=q->rear->next=NULL; + return OK; +} + +Status EnQueue(LinkQueue*q, ElemType e) { + Pq_node ptr; + ptr=(Pq_node)malloc(sizeof(Qnode)); + if(!ptr) + { + return ERROR; + } + ptr->data=e; + ptr->next=NULL; + ptr->previous=q->front; + q->rear->next=ptr; + q->rear=ptr; + return OK; +} + +Status DeQueue(LinkQueue *q,ElemType *e){ + if(EmptyQueue(*q)){ + return ERROR; + } + q->front=q->front->next; + *e=q->front->data; + return OK; +} + +bool EmptyQueue(LinkQueue q){ + if(q.front==q.rear){ + return true; + } + + return false; + +} +Status Add(Graph*g,int i,int j) { + if(i>=MAX_VEX||j>=MAX_VEX) + { + return ERROR; + } + g->arcs[i][j].eadj=1; + g->arcs[j][i].eadj=1; + + return OK; +} +Status CreatGraph(Graph*g) { + g->vers_num=9; + g->arcs_num=12; + int i=0; + int j=0; + for(i=0;ivers_num;i++) + { + for(j=0;jvers_num;j++) + { + g->arcs[i][j].eadj=0; + } + } + Add(g, 0, 1); Add(g, 0, 2); Add(g, 0, 3); Add(g, 0, 6); + Add(g, 1, 2); Add(g, 3, 4); Add(g, 3, 5); Add(g, 4, 5); + Add(g, 5, 7); Add(g, 6, 7); Add(g, 6, 8); Add(g, 7, 8); + return OK; + +} + +VerType ToFirstAdjVex(Graph g,int num) { + int i; + for(i=0;i=0;j=ToNextAdjVex(g,e,j)) + { + if(j==b){ + EnQueue(&q,j); + PrintFoot(q,a); + flag=true; + break; + } + if(!visited[j]){ + EnQueue(&q,j); + visited[j]=true; + } + + } + if(flag){ + break; + } + + } + +} +Status PrintFoot(LinkQueue q,VerType start) { + int track[MAX_VEX]; + Pq_node ptr; + int i=0,j; + + ptr=q.rear; + for(i=0;idata; + ptr=ptr->previous; + for(i=1;ptr->data!=start;i++){ + track[i]=ptr->data; + ptr=ptr->previous; + } + track[i]=ptr->data; + for( j=i;j>=0;j--) + {if(track[j]>=0) + { + printf("%d ",track[j]+1); + } + + } + return OK; +} +int main() +{ + Graph graph; + CreatGraph(&graph); + int i=0,j=0; + printf("到其他结点的最短路径为:\n"); + for(i=0;i<9;i++){ + for(j=0;j<9;j++) + { + if(j!=i) + { + printf("%d<->%d:",i+1,j+1); + BFSTraverse(graph,i,j); + printf("\n"); + } + } + } + return 0; +} \ No newline at end of file diff --git "a/2017-1/hx/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/._\346\213\254\345\217\267\345\214\271\351\205\215\347\232\204\346\243\200\351\252\214.c" "b/2017-1/hx/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/._\346\213\254\345\217\267\345\214\271\351\205\215\347\232\204\346\243\200\351\252\214.c" new file mode 100644 index 0000000000000000000000000000000000000000..51acf3238c3f401cac9a9d730255dbed106e658a GIT binary patch literal 4096 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^1EBI0G%X<0LE_vD4C2Z8xq68O1v#mDA*mH5u6fD%DVcfc5Dl+^R3rm~IYLct zYDr>BVo9P^wy%p%Vp3{Od|F~=PL^3-Nv>I8Vn#_`x`}aeW?qp=u4y7rb8aG#Q<7ht zVQuh{8iIbOcakF8yNxjc? z<5kNi2xhdIB;ScYT+I~I+xA&u^OVC>wW_G_gzXTtY1LYz8Ej)uT! z2#kinXb6mkz-S1JhQMeDjE2By2#kinXb22+2rvR20K#A(7m|@#tWcC%oL^d$oT`wP xUzDu?>>;M+m1O4UCFbN*D&(Z5l_(_TB<5uU`@&FNLz+VMKin%a408Yf0|2zpZ@K^g literal 0 HcmV?d00001 diff --git "a/2017-1/hx/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/._\346\225\260\345\210\266\350\275\254\346\215\242.c" "b/2017-1/hx/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/._\346\225\260\345\210\266\350\275\254\346\215\242.c" new file mode 100644 index 0000000000000000000000000000000000000000..648c7cc51b3f8573d4a673d31e94609fc9ea38d3 GIT binary patch literal 4096 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^1EBH>G%X<0LE`)j4C2Z8xq68O1v#mDA*mH5u6fD%DVcfc5Do8vR3-z1IYLct zYDr>BVo9P^wy%p%Vp3{Od|F~=PL^3-Nv>I8Vn#_`x`}aeW?qp=u4y7rb7@JMu7$Os zv5AqPxuu24r(I2EDYfY;1^1PX&5>w2`e0&;nAx_jBd#fDDzle-n4fI&BL9sN-@@X@ z?+d~-ULLCpH1fP-u=(wdj86@Pt=?M=K2e9{wO&b0;3@?8UmvsFd71*Aut*OqaiRF0;3@?8UmvsK+h0h z1X>2dU?3Ngky)%zlv$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^1EBI0G%X<0LE_vD4C2Z8xq68O1v#mDA*mH5u6fD%DVcfc5Dl+^R3rm~IYLct zYDr>BVo9P^wy%p%Vp3{Od|F~=PL^3-Nv>I8Vn#_`x`}aeW?qp=u4y7rb8aG#Q<7ht zVQug!MUg|tmUo8{WB1L&E@2F}GCW-LFGg($4et|J-NEwf!~LD|vl4Tagr*t#?-Z`p zIXk;ohyC}l#E->k{~HQT_ZPGJesDg2O_cA!>Cm^Vmya0i_u!EKo&0ty#Hpj?Xb6mk zz-S1JhQMeDjE2By2#kinXb6mkz-S1JhQL6F03*-=APfd_AsLy)3Pq{K`K3k4sS0WN wMcE3#9%5= + +#define M 1000 + +typedef int Elemtype; +typedef enum{ + ERROR, + OK +}Status; + +typedef struct Stack { + char string[M]; + Elemtype top; +}Stack; +void InitStack(Stack *s) +{ + s->top = -1; +} + +Status PushStack(Stack *s, char ch) +{ + if(s->top == M-1) { + return ERROR; + } + s->top++; + s->string[s->top] = ch; + return OK; +} + +Status PopStack(Stack *s, char *ch) +{ + if(s->top == -1) { + return ERROR; + } + *ch = s->string[s->top]; + s->top--; + return OK; +} + +Status GetTop(Stack *s, char *ch) +{ + if(s->top == -1) { + return ERROR; + } + *ch = s->string[s->top]; + return OK; +} +Status IsEmpty(Stack *s) +{ + if(s->top == -1) + { + return OK; + } + else { + return ERROR; + } +} +Elemtype MatchBracket(char ch1, char ch2) +{ + if(ch1 == '(' && ch2 == ')') { + return 1; + } + if(ch1 == '[' && ch2 == ']') { + return 1; + } + if(ch1 == '{' && ch2 == '}') { + return 1; + } + return 0; +} +int main() +{ + Stack s; + char str[M] = {0}, ch; + int i; + + InitStack(&s); + fprintf(stdout, "Input brackets:"); + fscanf(stdin, "%s", str); + for(i = 0; str[i] != 0; i++) { + switch(str[i]) { + case '(': + case '[': + case '{': + PushStack(&s, str[i]); + break; + case ')': + case ']': + case '}': + if(IsEmpty(&s)) { + printf("right bracket spilth.\n"); + return 0; + } else { + GetTop(&s, &ch); + if(MatchBracket(ch , str[i])) { + PopStack(&s, &ch); + } else{ + printf("left and right brackets are different.\n"); + return 0; + } + } + break; + default: + printf("Input error\n"); + } + } + if(IsEmpty(&s)) { + printf("Left and right brackets are matched.\n"); + } else { + printf("Left bracket spilth..\n"); + } + return 0; +} \ No newline at end of file diff --git "a/2017-1/hx/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\346\225\260\345\210\266\350\275\254\346\215\242.c" "b/2017-1/hx/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\346\225\260\345\210\266\350\275\254\346\215\242.c" new file mode 100644 index 00000000..bc0cad87 --- /dev/null +++ "b/2017-1/hx/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\346\225\260\345\210\266\350\275\254\346\215\242.c" @@ -0,0 +1,112 @@ +#include +#include +#include + +#define STACK_INIT_SIZE 100 +#define STACKINCREMENT 10 + +typedef int SElemType; +typedef struct _SqStack { + SElemType *base; + SElemType *top; + int stacksize; +}SqStack; +typedef enum { + false , + true +}bool; + +typedef enum { + OK, + ERROR, + OVERFLOW +} Status; + +Status InitStack (SqStack *S); +Status conversion (SqStack *, int , int); +Status Push (SqStack *S, SElemType e); +Status Pop (SqStack *S,SElemType *e); +bool IsStackEmpty (SqStack *S); + +Status InitStack (SqStack *S) +{ + S->base = (SElemType *)malloc(STACK_INIT_SIZE * + sizeof(SElemType)); + if(!S->base) { + return OVERFLOW; + } + + S->top = S->base; + S->stacksize = STACK_INIT_SIZE; + + return OK; +} + +Status Push (SqStack *S,SElemType e) { + if((S->top-S->base)>=S->stacksize) { + return ERROR; + } + *S->top++ = e; + return OK; +} + +Status Pop (SqStack *S,SElemType *e) +{ + if(IsStackEmpty(S)) + { + return ERROR; + } + + *e = *--S->top; + return OK; +} + +bool IsStackEmpty (SqStack *S) +{ + if(S) { + return S->base ==S->top; + } + return true; +} + +Status conversion (SqStack *S, int input, int d) +{ + SElemType e; + if(d > 10) { + return ERROR; + } + + while (input) + { + Push(S,input % d); + input = input / d; + } + while (!IsStackEmpty(S)) + { + Pop(S,&e); + printf("%d", e); + } + printf("\n\n"); + return OK; +} + +int main(int argc,char* argv[]) +{ + SqStack S; + int input=1348; + int d,i; + srand(time(NULL)); + //随机生成数 + for(i = 0;i < 5;i ++) { + d = rand ()%8+2; + input = rand()%1024; + + printf("随机十进制数为:%d\n",input); + printf("需要转化为%d进制\n",input); + InitStack(&S); + printf("数制转换结果为:"); + conversion (&S, input, d); + } + return 0; +} + diff --git "a/2017-1/hx/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\350\241\214\347\274\226\350\276\221.c" "b/2017-1/hx/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\350\241\214\347\274\226\350\276\221.c" new file mode 100644 index 00000000..9a2f7fcb --- /dev/null +++ "b/2017-1/hx/\347\254\254\344\270\211\346\254\241\344\275\234\344\270\232/\350\241\214\347\274\226\350\276\221.c" @@ -0,0 +1,105 @@ +#include +#include + +#define STACK_INIT_SIZE 100 +#define STACKINCREMENT 10 + +typedef char SElemType; +typedef enum{ + ERROR, + OK, + OVERFLOW +}Status; +typedef struct { + SElemType *base; + SElemType *top; + int stacksize; +}SqStack; + +Status InitStack(SqStack *S); +Status Push(SqStack *S,SElemType e); +Status Pop(SqStack *S,SElemType *e); +Status ClearStack(SqStack *S); +Status DestroyStack(SqStack *S) ; +void LineEdit(SqStack *S); + +Status InitStack(SqStack *S) { + S->base = (SElemType *)malloc(STACK_INIT_SIZE*sizeof(SElemType)); + if(!S->base) { + return OVERFLOW; + } + + S->top = S->base; + S->stacksize = STACK_INIT_SIZE; + + return OK; +} +Status Push(SqStack *S,SElemType e) { + if((S->top-S->base)>=S->stacksize) { + S->base = (SElemType*)realloc(S->base,(S->stacksize+STACKINCREMENT)*sizeof(SElemType)); + if(!S->base) { + return OVERFLOW; + } + S->top = S->base + S->stacksize; + S->stacksize += STACKINCREMENT; + } + *S->top++ = e; + return OK; +} +Status Pop(SqStack *S,SElemType *e) { + if(S->top == S->base) + return ERROR; + *e = *--S->top; + return OK; +} +Status ClearStack(SqStack *S) { + S->top = S->base; + return OK; +} +Status DestroyStack(SqStack *S) { + S->top = S->base; + free(S->base); + S->top = NULL; + S->base = NULL; + return OK; +} +void LineEdit(SqStack *S) +{ + char ch,c,*b; + InitStack(S); + ch = getchar(); + while( ch != EOF) + { + while(ch != EOF&&ch!='\n') + { + switch(ch) + { + case '#':Pop(S,&c); + break; + case '@':ClearStack(S); + break; + default : + Push(S, ch); + } + ch = getchar(); + } + b = S->base; + while(b != S->top) + { + printf("%c",*b); + b++; + } + ClearStack(S); + if( ch!=EOF) + ch = getchar(); + } + DestroyStack(S); +} +int main() +{ + SqStack s; + printf("input:\n"); + LineEdit(&s); + DestroyStack(&s); + return 0; +} diff --git "a/2017-1/hx/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/._\346\213\206\345\210\206\347\272\277\346\200\247\351\223\276\350\241\250.c" "b/2017-1/hx/\347\254\254\344\272\214\346\254\241\344\275\234\344\270\232/._\346\213\206\345\210\206\347\272\277\346\200\247\351\223\276\350\241\250.c" new file mode 100644 index 0000000000000000000000000000000000000000..4afb0ebfe396ea29dfb5fd5b77aedb11c94f85fa GIT binary patch literal 4096 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^1EBI5Xj(v~gT(n67{rtFbM+Dn3UX5QLQ*SAT=SCiQ!?|?AsXHTsZIt4bA+1Q z)RM%M#F9j-Y+o0j#H7@m__V~#oGi1vl3cUG#Eg=>bQ9y`%)BC#T+>9L=F*ZhT?=bN zV-q7ob4v@8Pv7|}UY&34-?Gi|uF-Nf5u<&t%u{X}?{vsMwIFEu?-^fr)!w|3ysiK0 z&V^_0-jmgr_&!_xPI3J7`0P|wla@G+B3&if-#_Pld!c1%suguWFnssk`p@deZt{k< z-PF$KI(p+w=d$=cYW%m}ENR*|OL@n)ce?g=Zhsu6DEYJ;;(x2W_=$%^fDl{SJBas2 z$ +#include +#include + +typedef struct LNode{ + int data; + struct LNode *next; +}LNode,*LinkList; + +void CreateList (LinkList *L,int n) +{ + LinkList p = (LinkList) malloc(sizeof(LNode)); + LinkList temp = p; + srand((unsigned)time( NULL ) ); + for(;n!=0;--n){ + p->next = (LinkList)malloc(sizeof(LNode)); + p->next->data = rand()%1024; + p=p->next; + } + p->next = NULL; + *L = temp->next; + free(temp); +} + +void Traverse1 (LinkList L) +{ + LNode *p = L; + while(p) { + printf("%d ",p->data); + p = p->next; + } + printf("\n"); +} +void Traverse2 (LinkList L) +{ + LNode *p = L->next; + do{ + printf("%d ",p->data); + p = p->next; + }while(p != L->next); + printf("\n"); +} +void SplitList(LinkList L,LinkList*pL1,LinkList*pL2) +{ + *pL1=(LNode*)malloc(sizeof(LNode)); + (*pL1)->data = 0; + (*pL1)->next = NULL; + *pL2=(LNode*)malloc(sizeof(LNode)); + (*pL2)->data = 0; + (*pL2)->next = NULL; + LinkList p,rear1 = *pL1,rear2=*pL2; + int count=0; + for(p = L;p != NULL;p = p->next) + { + ++count; + if(count%2) + { + (*pL1)->data++; + rear1->next = p; + rear1 = p; + } + else + { + (*pL2)->data++; + rear2->next = p; + rear2 = p; + } + } + rear1->next = (*pL1)->next; + rear2->next = (*pL2)->next; +} +int main() +{ + LinkList L,L1 = NULL,L2 = NULL; + int n; + + srand((unsigned)time( NULL ) ); + n = rand()%9+2; + printf(" 分解前的线性链表数据长度: %d\n",n); + /*scanf("%d",&n);*/ + CreateList(&L,n); + printf("分解前的线性链表数据:\n"); + Traverse1(L); + + SplitList(L,&L1,&L2); + printf("\n分解后的单循环链表L1数据:\n"); + Traverse2(L1); + printf("\n分解后的单循环链表L2数据:\n"); + Traverse2(L2); + return 0; +} diff --git "a/2017-1/hx/\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/._\344\272\214\345\217\211\346\240\221\347\232\204\351\201\215\345\216\206.c" "b/2017-1/hx/\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/._\344\272\214\345\217\211\346\240\221\347\232\204\351\201\215\345\216\206.c" new file mode 100644 index 0000000000000000000000000000000000000000..7c0cd6f8bec7c935a77e968a824cb4cbc523acfa GIT binary patch literal 4096 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^1EBH@G%X<0LE`)j4C2Z8xq68O1v#mDA*mH5u6fD%DVcfc5Do8vR3rm~IYLct zYDr>BVo9P^wy%p%Vp3{Od|F~=PL^3-Nv>I8Vn#_`x`}aeW?qp=u4y7rb7@JMu7$Os zv5AqPxuu24rxcq=;h1~Dk2Y2)#l=pXcjhV&2NR1>;S1@9GA%0{Zu?neIwrX%ckP*M z!e(Y^A=OzQnY+yY>0R^nS2Vu0dDXq0@}bKjnzQgx%Y9ip!9{9y$E^*jZ@yl90pi?I zax?@+Ltr!nMnhmU1V%$(Gz3ONU^E0qLtr!nMnhmALx2%zIS7M+Tu4S{u|iR5aeir0 za;idFeo?kUW?o5ZUP)$tUSdv8r9w_>T8TnZPGVj*urCbNHKZw2|HHi^!yxznKLEnJ BYHt7l literal 0 HcmV?d00001 diff --git "a/2017-1/hx/\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/\344\272\214\345\217\211\346\240\221\347\232\204\351\201\215\345\216\206.c" "b/2017-1/hx/\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/\344\272\214\345\217\211\346\240\221\347\232\204\351\201\215\345\216\206.c" new file mode 100644 index 00000000..d15e367e --- /dev/null +++ "b/2017-1/hx/\347\254\254\344\272\224\346\254\241\344\275\234\344\270\232/\344\272\214\345\217\211\346\240\221\347\232\204\351\201\215\345\216\206.c" @@ -0,0 +1,90 @@ +#include +#include +typedef char TElemType; +typedef struct BiTNode { + TElemType data; + struct BiTNode *lchild,*rchild; +}BiTNode,*BiTree; +typedef enum { + ERROR, + OK, + OVERFLOW +}Status; + +Status CreateBitree (BiTree *T,int i); +Status PostOrderTraverse(BiTree T); +Status InOrderTraverse(BiTree T); +Status PostOrderTraverse(BiTree T); + +char*s[]={"ABDG###EH##I#K##C#F##","ABD#F##CE###"};int si[]={0,0}; + +Status CreateBitree (BiTree *T,int i) +{ + char ch; + //scanf("%c",&ch); + ch=s[i][si[i]++]; + if(ch == '#') + *T =NULL; + else{ + if(! (*T = (BiTNode *)malloc(sizeof(BiTNode)) )) + exit(OVERFLOW); + (*T)->data = ch; + CreateBitree(&(*T)->lchild,i); + CreateBitree(&(*T) ->rchild,i); + } + return OK; +} +Status PreOrderTraverse(BiTree T) +{ + if(T){ + printf("%c",T->data); + PostOrderTraverse(T->lchild); + PostOrderTraverse(T->rchild); + } + return OK; +} +Status InOrderTraverse(BiTree T) +{ + if(T){ + PostOrderTraverse(T->lchild); + printf("%c",T->data); + PostOrderTraverse(T->rchild); + } + return OK; +} +Status PostOrderTraverse(BiTree T) +{ + if(T){ + PostOrderTraverse(T->lchild); + PostOrderTraverse(T->rchild); + printf("%c",T->data); + } + return OK; +} +int main() +{ + BiTree tree[]={NULL,NULL}; + int i; + for(i=0;i!=2;++i) + { + printf("%s\n",s[i]); + + CreateBitree(&tree[i],i); + + printf("%-6s","pre:"); + PreOrderTraverse(tree[i]); + printf("\n"); + + printf("%-6s","in:"); + InOrderTraverse(tree[i]); + printf("\n"); + + printf("%-6s","post:"); + PostOrderTraverse(tree[i]); + printf("\n"); + + printf("\n"); + } + + return 0; +} diff --git "a/2017-1/hx/\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/.DS_Store" "b/2017-1/hx/\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/.DS_Store" new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIk*Y|peR=07!nd> zJ?rFuhz^DdtcpejM?+vV1V%$(Gz3ONU^E0qLtr!nMnhmU1V%$(Gz3ONfXX4j2s96b z!9Xq~BePhcD784hv?w`MAuYcsTOl*ABsH%jGe0jeC#O;&CpE1^At@&@FB{m^h3Xp8 P6srH>UXfvt`~M#R%-A0@ literal 0 HcmV?d00001 diff --git "a/2017-1/hx/\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/._\344\272\214\345\217\211\346\216\222\345\272\217\346\240\221.cpp" "b/2017-1/hx/\347\254\254\345\205\253\346\254\241\344\275\234\344\270\232/._\344\272\214\345\217\211\346\216\222\345\272\217\346\240\221.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..b9d11e4d3c49a84c8009370bcc7fed5ce8935721 GIT binary patch literal 4096 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^1EBI0G%X<0LE_vD4C2Z8xq68O1v#mDA*mH5u6fD%DVcfc5Dl+^R3rm~IYLct zYDr>BVo9P^wy%p%Vp3{Od|F~=PL^3-Nv>I8Vn#_`x`}aeW?qp=u4y7rb8aG#Q<7ht zVQuiq`E19W9`8=cNeA90IKL6ET=$&yG6SdDR&}LUt#7_A^5hJ$-L4ux*Nj7U`W${& zpTgH?FIvy+liaU%5PrjqFr(|xMM;JAx<47M?+vV z1V%$(Gz3ONU^E0qLtr!nMnhmU1V%$(Gz11Z1Q>x10AVnY3(3eVRwzm>&Mz%WPE|?J3N)(cE67#ZwePO7sAx)wBAMO +#include +#define MAX 20 +int num[] = {8,10,14,3,1,6,4,7,5,19,22,30}; +int searchnum[] = {13,8,5,20,6}; +int flag; +enum +{ + FALSE, + TRUE +}; +typedef struct BiTNode { + int data; + struct BiTNode *lchild, *rchild; +} BiTNode,*BiTree; +typedef enum +{ + OK, + ERROR, + OVERFLOW +}Status; + +Status PreOrderTraverse(BiTree T); +int SearchBST( BiTree T, int key, BiTree f, BiTree *p ) ; +int InsertBST( BiTree *T, int key ); +Status Delete(BiTree *p); +int DeleteBST(BiTree *T, int kval); + +Status PreOrderTraverse(BiTree T) +{ + if(T){ + printf("%d ",T->data); + PreOrderTraverse(T->lchild); + PreOrderTraverse(T->rchild); + } + return OK; +} + +int SearchBST( BiTree T, int key, BiTree f, BiTree *p ) +{ + BiTree s; + if( !T ) + { + *p = f; + return FALSE; + } + else + { + while( T ) + { + if( key == T->data ) + { + *p = T; + return TRUE; + } + if( key > T->data ) + { + s = T; + T = T->rchild; + } + else + { + s = T; + T = T->lchild; + } + } + *p = s; + return FALSE; + } +} +int InsertBST( BiTree *T, int key ) +{ + BiTree p, s; + if( !SearchBST( *T, key, NULL, &p ) ) + { + s = (BiTree)malloc(sizeof(BiTNode)); + s->data = key; + s->lchild = s->rchild = NULL; + if( !p ) + *T = s; + else if( key > p->data ) + p->rchild = s; + else + p->lchild = s; + return TRUE; + } + return FALSE; +} +Status Delete(BiTree *p) { + + BiTree q,s ; + if(!&(*p)->rchild && !&(*p)->lchild) + { + p = NULL; + } + else if (!(*p)->rchild) { + q = *p; + *p = (*p)->lchild; + free(q); + } + else if (!(*p)->lchild) { q = *p; + *p = (*p)->rchild; + free(q); + } + else { + q = *p; + s = (*p)->lchild; + while(s->rchild) { + q = s; + s = s->rchild; + } + (*p)->data = s->data; + if(q != *p) { + q->rchild = s->lchild; + } else { + q->lchild = s->lchild; + } + free(s); + } + return OK; +} +int DeleteBST(BiTree *T, int kval) { + + if(!(*T)) { + return FALSE; + } + else { + if(EQ(kval, (*T)->data)) { + Delete (T); + return TRUE; + } + else if(LT(kval, (*T)->data)) { + return DeleteBST(&(*T)->lchild, kval); + } + else { + return DeleteBST(&(*T)->rchild, kval); + } + } +} + +int main() +{ + int j; + BiTree T=NULL; + for(j = 0;j < 12;j++) + { + InsertBST(&T, num[j]); + } + PreOrderTraverse(T); + for(j = 0;j <5;j++) + { + if(!InsertBST(&T, searchnum[j])){ + DeleteBST(&T,searchnum[j]); + } + printf("\n"); + PreOrderTraverse(T); + } + return 0; +} diff --git "a/2017-1/hx/\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/._\350\256\241\347\256\227\344\272\214\345\217\211\346\240\221\351\253\230\345\272\246\344\270\216\345\256\275\345\272\246.c" "b/2017-1/hx/\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/._\350\256\241\347\256\227\344\272\214\345\217\211\346\240\221\351\253\230\345\272\246\344\270\216\345\256\275\345\272\246.c" new file mode 100644 index 0000000000000000000000000000000000000000..95cecb666c7a8e0175c4d2edab533c701570e377 GIT binary patch literal 4096 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^1EBH@G%X<0LE`)j4C2Z8xq68O1v#mDA*mH5u6fD%DVcfc5Do8vR3rm~IYLct zYDr>BVo9P^wy%p%Vp3{Od|F~=PL^3-Nv>I8Vn#_`x`}aeW?qp=u4y7rb7@JMu7$Os zv5AqPxuu24r{qKj+X64)+2=J*c||L15KR;5F-kk%_-1C)pLKVh@6P*g7;a-tPw(`=^etj}p{+W)&g^bP+FgZj%#M~WpHlJR+#R^5K#rdU0 z$*Bry`9;|ZnRz9tc_o?od5JkWl?pkjX(b9tIf;4Mz`ih4*N~=A{SWtw41?VN{{WRw BZJ+=E literal 0 HcmV?d00001 diff --git "a/2017-1/hx/\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\350\256\241\347\256\227\344\272\214\345\217\211\346\240\221\351\253\230\345\272\246\344\270\216\345\256\275\345\272\246.c" "b/2017-1/hx/\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\350\256\241\347\256\227\344\272\214\345\217\211\346\240\221\351\253\230\345\272\246\344\270\216\345\256\275\345\272\246.c" new file mode 100644 index 00000000..8081080b --- /dev/null +++ "b/2017-1/hx/\347\254\254\345\205\255\346\254\241\344\275\234\344\270\232/\350\256\241\347\256\227\344\272\214\345\217\211\346\240\221\351\253\230\345\272\246\344\270\216\345\256\275\345\272\246.c" @@ -0,0 +1,115 @@ +#include +#include +typedef char TElemType; +typedef struct BiTNode { + TElemType data; + struct BiTNode *lchild,*rchild; +}BiTNode,*BiTree; +typedef enum { + ERROR, + OK, + OVERFLOW +}Status; +char*s[2]={"ABDG###EH##I#K##C#F##","ABD#F##CE###"}; +int index2[2]={0}; + +Status CreateBitree (BiTree *T,int index) +{ + //char ch; + //scanf("%c",&ch); + if(s[index][index2[index]] == '#') + { + *T =NULL; + ++index2[index]; + } + else + { + if((*T = (BiTNode*)malloc(sizeof(BiTNode)))==NULL) + { + exit(OVERFLOW); + } + (*T)->data = s[index][index2[index]]; + ++index2[index]; + CreateBitree(&(*T)->lchild,index); + CreateBitree(&(*T) ->rchild,index); + } + return OK; +} +Status PostOrderTraverse(BiTree T,int*leaf_count,int*nonleaf_count) +{ + if(T!=NULL) + { + if(T->lchild==NULL&&T->rchild==NULL) + { + ++*leaf_count; + } + else + { + ++*nonleaf_count; + } + PostOrderTraverse(T->lchild,leaf_count,nonleaf_count); + PostOrderTraverse(T->rchild,leaf_count,nonleaf_count); + printf("%c",T->data); + } + return OK; +} +void FindDepthest(BiTree T,int layer,int*depth) +{ + if(layer>*depth) + { + *depth=layer; + } + if(T->lchild!=NULL) + { + FindDepthest(T->lchild,layer+1,depth); + } + if(T->rchild!=NULL) + { + FindDepthest(T->rchild,layer+1,depth); + } +} +void FindBitreeWidth(BiTree T,int layer,int*width[]) +{ + if(T->lchild!=NULL) + { + ++(*width)[layer-1]; + FindBitreeWidth(T->lchild,layer+1,width); + } + if(T->rchild!=NULL) + { + ++(*width)[layer-1]; + FindBitreeWidth(T->rchild,layer+1,width); + } +} +int main() +{ + int i; + for(i=0;i!=2;++i) + { + BiTree tree=NULL; + int tDepth = 1; + CreateBitree(&tree,i); + + int temp1=0,temp2=0; + PostOrderTraverse(tree,&temp1,&temp2); + printf("\n"); + + temp1=0; + FindDepthest(tree,1,&temp1); + printf("二叉树的高度为%d",temp1); + printf("\n"); + + int*temp3=(int*)calloc(temp1,sizeof(int)); + FindBitreeWidth(tree,1,&temp3); + int j,max=0; + for(j=0;j!=temp1;++j) + { + if(temp3[j]>max) + { + max=temp3[j]; + } + } + printf("二叉树的宽度为%d\n",max); + } + return 0; +} \ No newline at end of file diff --git "a/2017-1/hx/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/._\345\215\225\345\220\221\351\230\237\345\210\227\345\237\272\346\234\254\346\223\215\344\275\234.cpp" "b/2017-1/hx/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/._\345\215\225\345\220\221\351\230\237\345\210\227\345\237\272\346\234\254\346\223\215\344\275\234.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..a95230277cb19df5511de23b2e6af83e6fd8f692 GIT binary patch literal 4096 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^1EBI5Xj(v~gT(n67{rtFbM+Dn3UX5QLQ*SAT=SCiQ!?|?AsXHTsZIt4bA+1Q z)RM%M#F9j-Y+o0j#H7@m__V~#oGi1vl3cUG#Eg=>bQ9y`%)BC#T+>9L=F*ZhT?=bN zV-q7ob4v@8PY>^B7|vv$xNnm8`V3Zv{mU~l3Odddc^~kS&R;G%{|?K%m7YPrQs>=N z;$Vn8ulUvdLe0Ob;;MZH!aiT4a+o+%duN&H37rd;pS)t%;>xV2sUM!Q{XVk(WqXyn z$;v#{Pl^?9TC@WT|L?q|b+f~9)AaqD=1uCC$yR^qwsc93={|SIt2|w)fw!Y?K)g3f zj)uT!2#kinXb6mkz-S1JhQMeDjE2By2#kinXb4a<1Q>yafiM`zg=AzFD-@*`=a&{G zrz)i77iBAC=9Q%8m1O4UCFbN*D&(Z5l_(_TB<5uU`@&FNLz+VMKin%a408Yf0{}*l Bg}ML$ literal 0 HcmV?d00001 diff --git "a/2017-1/hx/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/._\345\221\275\344\273\244\350\241\214\345\256\236\347\216\260\350\241\250\350\276\276\345\274\217\346\261\202\345\200\274.cpp" "b/2017-1/hx/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/._\345\221\275\344\273\244\350\241\214\345\256\236\347\216\260\350\241\250\350\276\276\345\274\217\346\261\202\345\200\274.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..edfd5f3e3a09b283f4d94c684c816b5ad82bd252 GIT binary patch literal 4096 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^1EBH>G%X<0LE`)j4C2Z8xq68O1v#mDA*mH5u6fD%DVcfc5Do8vR3-z1IYLct zYDr>BVo9P^wy%p%Vp3{Od|F~=PL^3-Nv>I8Vn#_`x`}aeW?qp=u4y7rb7@JMu7$Os zv5AqPxuu24rvuDAJKfju{)@Nz{Xrq>JoDZS{g;=Ee!BeUPQsfC14oOs>v%0@PU2yn zb*6uAUXfvt`~M#R|B-gP literal 0 HcmV?d00001 diff --git "a/2017-1/hx/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/\345\215\225\345\220\221\351\230\237\345\210\227\345\237\272\346\234\254\346\223\215\344\275\234.cpp" "b/2017-1/hx/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/\345\215\225\345\220\221\351\230\237\345\210\227\345\237\272\346\234\254\346\223\215\344\275\234.cpp" new file mode 100644 index 00000000..26715836 --- /dev/null +++ "b/2017-1/hx/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/\345\215\225\345\220\221\351\230\237\345\210\227\345\237\272\346\234\254\346\223\215\344\275\234.cpp" @@ -0,0 +1,248 @@ +#include +#include + +#define STACK_INIT_SIZE 100 +#define STACKINCREMENT 10 + +typedef char SElemType; + +typedef enum{ + ERROR, + OK, + OVERFLOW +}Status; +typedef struct { + int top; + int stacksize; + SElemType stack[STACK_INIT_SIZE]; + double data[STACK_INIT_SIZE]; +}SqStack; + +Status InitStack(SqStack *S); +Status Push(SqStack *S,SElemType e); +Status Pop(SqStack *S,SElemType *e); +Status ClearStack(SqStack *S); +Status DestroyStack(SqStack *S) ; +Status GetTop(SqStack *S,SElemType ); +Status EmptyStack(SqStack *S); +int GetLength(SqStack S); +void TranslateExpress(char s1[],char s2[]); +double ComputeExpress(char a[]); + +Status InitStack(SqStack *S) +{ + int i; + S->top = 0; + for (i = 0;i < STACK_INIT_SIZE;i++) + { + S->data[i] = 0; + } + return OK; +} +Status EmptyStack(SqStack *S) +{ + if(0 == S->top) + { + return OK; + } + else + { + return ERROR; + } +} +Status GetTop(SqStack S,SElemType *e) +{ + if(S.top <= 0) + { + printf("’ª“—æ≠ø’£°\n"); + return ERROR; + } + else + { + *e = S.stack[S.top-1]; + return OK; + } +} +Status Push(SqStack *S,SElemType e) + +{ + if(S->top >= STACK_INIT_SIZE-1) + { + printf("’ª“—¬˙£¨≤ªƒ‹»Î’ª£°"); + return ERROR; + } + else + { + S->stack[S->top] = e; + S->top++; + return OK; + } +} +Status Pop(SqStack *S,SElemType *e) +{ + if(S->top <= 0) + { + printf("’ª“—æ≠√ª”–‘™Àÿ£¨≤ªƒ‹≥ˆ’ª£°\n"); + return ERROR; + } + else + { + S->top--; + *e = S->stack[S->top]; + return OK; + } +} +int GetLength(SqStack S) +{ + return S.top; +} +Status ClearStack(SqStack *S) +{ + S->top = 0; + return OK; +} +void TranslateExpress(SElemType s1[],SElemType s2[]) +{ + SqStack s; + char ch; + SElemType e; + int i = 0,j = 0; + InitStack(&s); + ch = s1[i]; + i++; + while( ch != '\0') + { + switch(ch){ + case '(' : + Push(&s,ch); + break; + case ')' : + while(GetTop(s,&e) && e != '(') + { + Pop(&s,&e); + s2[j] = e; + j++; + } + Pop(&s,&e); + break; + case '+' : + case '-' : + while (GetTop(s,&e) && e !='(') + { + Pop(&s,&e); + s2[j]= e; + j++; + } + Push(&s,ch); + break; + case '*' : + case '/' : + while(!EmptyStack(&s) && GetTop(s,&e) && e == '/' || e == '*') + { + Pop(&s,&e); + s2[j]= e; + j++; + } + Push(&s,ch); + break; + default : + while(ch >= '0'&&ch <= '9') + { + s2[j] = ch; + j++; + ch = s1[i]; + i++; + } + i--; + s2[j] = ' '; + j++; + } + ch = s1[i]; + i++; + + } + while(!EmptyStack(&s)) + { + Pop(&s,&e); + s2[j]= e; + j++; + } + s2[j]= '\0'; +} +double ComputeExpress(SElemType a[]) +{ + double val,num1,num2,result; + int i = 0; + SqStack s; + s.top = -1; + while (a[i] != '\0') + { + if (a[i] !=' ' && a[i] >='0' &&a[i] <='9') + { + val = 0; + while (a[i] != ' ') + { + val = val*10 + a[i]- '0'; + i ++; + } + s.top++; + s.data[s.top] = val; + } + else + { + switch(a[i]) + { + case '+': + num1 = s.data[s.top]; + s.top--; + num2 = s.data[s.top]; + s.top--; + result = num1+num2; + s.top++; + s.data[s.top] = result; + break; + case '-': + num1 = s.data[s.top]; + s.top--; + num2 = s.data[s.top]; + s.top--; + result = num2-num1; + s.top++; + s.data[s.top] = result; + break; + case '*': + num1 = s.data[s.top]; + s.top--; + num2 = s.data[s.top]; + s.top--; + result = num1*num2; + s.top++; + s.data[s.top] = result; + break; + case '/': + num1 = s.data[s.top]; + s.top--; + num2 = s.data[s.top]; + s.top--; + result = num2/num1; + s.top++; + s.data[s.top] = result; + break; + } + i++; + } + } + return result; +} +int main() +{ + SElemType a[STACK_INIT_SIZE],b[STACK_INIT_SIZE]; + double f; + printf("请输入一个表达式"); + gets(a); + TranslateExpress(a,b); + printf("后缀表达式是:%s\n",b); + f = ComputeExpress(b); + printf("计算结果是:%.2lf\n",f); + return 0; +} diff --git "a/2017-1/hx/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/\345\221\275\344\273\244\350\241\214\345\256\236\347\216\260\350\241\250\350\276\276\345\274\217\346\261\202\345\200\274.cpp" "b/2017-1/hx/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/\345\221\275\344\273\244\350\241\214\345\256\236\347\216\260\350\241\250\350\276\276\345\274\217\346\261\202\345\200\274.cpp" new file mode 100644 index 00000000..8780002e --- /dev/null +++ "b/2017-1/hx/\347\254\254\345\233\233\346\254\241\344\275\234\344\270\232/\345\221\275\344\273\244\350\241\214\345\256\236\347\216\260\350\241\250\350\276\276\345\274\217\346\261\202\345\200\274.cpp" @@ -0,0 +1,193 @@ +#include +#include + +typedef int QElemType; +typedef struct QNode +{ + QElemType data; + struct QNode *next; +}QNode,*QueuePtr; +typedef struct +{ + QueuePtr front; + QueuePtr rear; +}LinkQueue; +typedef enum{ + OK, + ERROR, + OVERFLOW +}Status; + +Status InitQueue (LinkQueue*Q); +Status DestroyQueue (LinkQueue Q); +Status EnQueue (LinkQueue *Q,QElemType e); +Status DeQueue (LinkQueue Q,QElemType *e); +Status CreateQueue(LinkQueue*L,int n); +Status Travel(LinkQueue Q); +Status backTravel(QueuePtr,QueuePtr); +Status ClearQueue(LinkQueue Q); +Status GetHead (LinkQueue Q,QElemType e); +int QueueEmpty(QueuePtr,QueuePtr); +int GetLength (LinkQueue Q); + + +Status InitQueue (LinkQueue*Q) +{ + Q->front = NULL; + Q->rear = NULL; + return OK; +} +Status DestroyQueue (LinkQueue*Q) +{ + QueuePtr temp; + while(Q->front) + { + temp = Q->front ->next; + free(Q->front); + Q->front = temp; + } + return OK; +} +Status EnQueue (LinkQueue *Q,QElemType e) +{ + QueuePtr p = (QueuePtr) malloc (sizeof(QNode)); + if (!p) + return OVERFLOW; + p->data = e; + p ->next = NULL; + if(Q->front!=NULL) + { + Q->rear->next = p; + } + else + { + Q->front=p; + } + Q->rear = p; + return OK; +} +Status DeQueue (LinkQueue*Q,QElemType *e) +{ + QueuePtr p; + if (Q->front == NULL) + { + return ERROR; + } + p= Q->front; + *e = p->data; + Q->front = p->next; + free(p); + return OK; +} +Status Travel(LinkQueue Q) +{ + QueuePtr p = Q.front; + printf("\n正向遍历:\n"); + while(p != NULL) + { + printf("%d ",p->data); + p = p->next; + } + printf("\n"); + return OK; +} +//“—÷™∂”Œ≤‘™Àÿ£¨∑¥œÚ±È¿˙µΩ∂” ◊ +Status backTravel(QueuePtr start,QueuePtr end) +{ + if(start!=end) + { + backTravel(start->next,end); + } + printf("%d ",start->data); + return OK; +} +Status CreateQueue(LinkQueue*L,int n) +{ + printf("\n 输入数据:"); + QueuePtr p = NULL; + int i ; + L->front = NULL; + for(i=0;idata); + if(i==0)L->rear=p; + p->next = L->front; + L->front = p; + } + return OK; +} +int QueueEmpty(QueuePtr start,QueuePtr end) +{ + if(start ==end) + { + return 1; + } + else + { + return 0; + } +} +int GetLength (LinkQueue Q) +{ + QueuePtr p; + int n=0; + p = Q.front; + while(p != NULL) + { + n++; + p = p->next; + } + return n; +} +Status GetHead (LinkQueue Q,QElemType e) +{ + if(!QueueEmpty) + { + e = Q.front->data; + return OK; + } + else + { + return ERROR; + } +} +Status ClearQueue(LinkQueue *Q) +{ + QueuePtr p,q; + Q->rear = Q->front; + p = Q->front; + Q->front = NULL; + while(p) + { + q = p; + p=p->next; + free(q); + } + return OK; +} +int main () +{ + LinkQueue Q={0,0}; + int n; + QElemType e=7,s; + InitQueue (&Q); + printf("请输入数据个数:"); + scanf("%d",&n); + + CreateQueue(&Q,n); + printf("\n 输出长度:%d\n", GetLength(Q)); + + Travel(Q); + printf("反向遍历:\n"); + backTravel(Q.front,Q.rear); + + printf("\n"); + EnQueue (&Q,e); + + Travel(Q); + printf("反向遍历:\n"); + backTravel(Q.front,Q.rear); + + DestroyQueue(&Q); + return 0; +} \ No newline at end of file