您好,登錄后才能下訂單哦!
內(nèi)容過程中中,把內(nèi)容過程中較好的內(nèi)容段做個珍藏,如下內(nèi)容段是關(guān)于C++順序存儲的線性表的內(nèi)容,希望對各位有所幫助。
#include <stdio.h>
#define OK 1
#define ERR 0
#define LIST_INIT_SIZE 100
#define LIST_INCREMENT 10
#define ElemType char
typedef struct {
} SqList;
{
if(NULL == aList->elem)return ERR;
aList->listSize = LIST_INIT_SIZE;
aList->length = 0;
return OK;
}
{
int i;
if( index<0 || index>aList->length ){
printf("Error : Insert %c to wrong position %dn",e,index);
}
if( aList->listSize <= aList->length )
{
if(NULL == aList->elem) return ERR;
aList->listSize += LIST_INCREMENT;
}
printf("Insert %c to position %dn",e,index );
i = aList->length;
while(i>index)
{
aList->elem[i] = aList->elem[i-1];
i--;
}
aList->elem[index] = e;
aList->length++;
return OK;
}
{
int i = index;
if(i<0 || i>=aList->length)return ERR;
i = index;
while(i<aList->length-1)
{
aList->elem[i] = aList->elem[i+1];
i++;
}
aList->length--;
return OK;
}
int ListTraverse(SqList aList)
{
int i=0;
while(i < aList.length){
printf("%ct",aList.elem[i]);
i++;
}
printf("n");
return OK;
}
{
SqList aList ;
char element;
int position;
InitList( &aList );
while(1){
printf("Please input element and position to insert in (input ; to quit) :n");
scanf("%1s,%d",&element,&position);
if(';' == element) break;
ListInsert(&aList,element,position);
}
ListDelete(&aList,&element,0);
ListTraverse(aList);
printf("length :%d . n",aList.length);
return OK;
}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。