严蔚敏版数据结构所有算法代码36388

严蔚敏版数据结构所有算法代码 ------------------------线性数据结构----------------------------- 2013年7月 //线性表、链表 //栈、队列 //数组、广义表 //串 -------------------------线性表---------------------- typedef struct { char name[20];//注意如果应用指针的形式 //在初始化每个结点时一定要先为结点中的每个变量开辟内存空间 char sex; char addr[100]; unsigned int age; char phonenum[20]; }node;//结点描述 typedef struct { node *p; int length;//当前顺序表长度 int listsize;//当前分配的线性表长度 }list;//线性表描述 list L;//定义一个线性表 int initlistlist ifl.p exit1; l.length0; l.listsizeLIST_INIT_SIZE; return true; } void destroylistlist printf“销毁成功\n“; } else printf“线性表不存在\n“; } int clearlistlist return false; } else { freel.p; l.pnode*mallocl.listsize*sizeofnode; l.length0; } return true; } int listemptylist else return false; } int getelemlist else el.p[i-1]; return true; } int priorelemlist else pre_el.p[i-1]; return true; } int nextelemlist else next_el.p[i1]; return true; } int insertlistlist ifil.length1 return false; ifl.lengthl.listsize { l.pnode *reallocl.p,l.listsizeLISTINCREMENT*sizeofnode; ifl.p exit1; l.listsizeLISTINCREMENT; } k forqqk;q-- *q1*q; *ke; l.length; return true; } int deletelistlist int ji-1; ifil.length return false; el.p[i-1]; forqjnext; qp-next; ifpNULL printf“链表为空无法实现逆置操作\n“; else { whileqNULL { p-nexthead2-next; head2-nextp; pq; qq-next; } p-nexthead2-next; head2-nextp; printf“逆置成功\n“; } } void InsertListslist plist *mallocsizeoflist; qhead; whileq-nextNULL qq-next; p-nextq-next; q-nextp; p-datae; } void InvertedListsqlist phead-next; qp-next; kq-next; p-nextNULL; whilekNULL { q-nextp; pq; qk; kk-next; } q-nextp; head-nextq;