第一次作业(河工大廊坊)
//staus PriorElem_Sq(L,cur_e,&pre_e)若cur_e是L的数据元素,且不是第一个,则用pre_e返回它的前驱,否则操作失败,pre_e无定义
Staus PriorElem_Sq(L,cur_e,&pre_e){ int i=0; p=L.elem; while(i<L.elem){ if(i==0&&*p==cur_e) { p++; contune; } if(*p==cur_e){ *pre_e=*--p; return OK; } i++,p++; } return ERROR; }
第二次作业
int Listlength_L(Linklist L)求带头单链表的长度
第三次作业
题目:试写一个算法,识别依次读入的一个以‘@’作为结束符的字符序列是否为形如“序列1&序列2”模式的字符序列。其中序列1和序列2中都不包含字符‘&’,且序列2是序列1的逆序列。如“a+b&b+a”。
官方答案:
BOOL Symmetry(char a[]){ int i=0; Stack s; InitStack(s); ElemType x; while(a[i]!='&' && a[i]){ Push(s,a[i]); i++; } if(a[i]) return FALSE; i++; while(a[i]){ Pop(s,x); if(x!=a[i]){ DestroyStack(s); return FALSE; } i++; } return TRUE; }
我的写法
略