精品专区-精品自拍9-精品自拍三级乱伦-精品自拍视频-精品自拍视频曝光-精品自拍小视频

網(wǎng)站建設(shè)資訊

NEWS

網(wǎng)站建設(shè)資訊

c語(yǔ)言locates函數(shù) r語(yǔ)言locator函數(shù)

誰(shuí)能用c語(yǔ)言寫(xiě)list的方法 insert delete locate length

#include time.h

創(chuàng)新互聯(lián)專(zhuān)注于永靖網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠(chéng)為您提供永靖營(yíng)銷(xiāo)型網(wǎng)站建設(shè),永靖網(wǎng)站制作、永靖網(wǎng)頁(yè)設(shè)計(jì)、永靖網(wǎng)站官網(wǎng)定制、微信小程序定制開(kāi)發(fā)服務(wù),打造永靖網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供永靖網(wǎng)站排名全網(wǎng)營(yíng)銷(xiāo)落地服務(wù)。

#include stdio.h

#define NULL -2

#define ERROR -1

#define OK 1

#define TRUE 2

#define FALSE 3

#define Boolen int

#define Status int

#define LIST_INIT_SIZE 3

#define LIST_INCREMENT 2

#define NAME_LEN 13

#define DES_LEN 30

char ErrDescription[DES_LEN];

typedef struct{

int NO;

char Name[NAME_LEN];

enum{male,female} Sex;

int Age;

char Tel[15];

char Inserttime[64];

}ElemType,*ElemPointer;

typedef struct{

ElemPointer base; //基址

int length; //表長(zhǎng)

int listsize; //內(nèi)存占用

int elemcount; //記錄數(shù)

}SqList,*SqPointer;

int ErrorEXP(int i)

{

switch(i)

{ case 1: strcpy(ErrDescription,"InitList::(ElemType *)malloc(LIST_INIT_SIZE * sizeof(ElemType)) 空間申請(qǐng)失敗");break;

case 2: strcpy(ErrDescription,"IncreaseList::(ElemType *)realloc(L-base,(L-length + LIST_INCREMENT) * sizeof(ElemType)) 空間申請(qǐng)失敗");break;

case 3: strcpy(ErrDescription,"if(!L-base) return Error; SqList不存在");break;

case 4: strcpy(ErrDescription,"GetElem:: i 越界");break;

case 5: strcpy(ErrDescription,"ListInsert:: i 越界");break;

case 6: strcpy(ErrDescription,"ListInsert:: CALL IncreaseList(L)==ERROR return Error 鄰接空間申請(qǐng)失敗,由ListInsert返回");break;

case 7: strcpy(ErrDescription,"ListDelete:: i 越界");break;

case 8: strcpy(ErrDescription,"KeyInList:: i 越界");break;

case 9: strcpy(ErrDescription,"KeyInList:: CALL ListInsert(L,i,temp)==ERROR return Error 鄰接空間申請(qǐng)失敗,由KeyInList返回");break;

case 10: strcpy(ErrDescription,"ScanfList:: CALL KeyInList(L,i++)==ERROR return Error");break;

}

puts("!!!!!!!!!!!!!!! ERROR !!!!!!!!!!!!!!!\n");

puts(ErrDescription);

puts("\n!!!!!!!!!!!!!!! ERROR !!!!!!!!!!!!!!!\n");

return ERROR;

}

Status InitList(SqPointer L)

{

L-base = 0; //不可不要!!! 去掉后即使(ElemType *)malloc(LIST_INIT_SIZE * sizeof(ElemType))失敗,系統(tǒng)也會(huì)認(rèn)為正常

L-base = (ElemType *)malloc(LIST_INIT_SIZE * sizeof(ElemType));

if(!L-base) return ErrorEXP(1); //空間申請(qǐng)失敗,返回

L-length = LIST_INIT_SIZE;

L-listsize = L-length * sizeof(ElemType);

L-elemcount = 0;

return OK;

}

Status IncreaseList(SqPointer L)

{

ElemPointer newbase;

newbase = (ElemType *)realloc(L-base,(L-length + LIST_INCREMENT) * sizeof(ElemType));

if(!newbase) return ErrorEXP(2);

L-base = newbase;

L-length += LIST_INCREMENT;

L-listsize = L-length * sizeof(ElemType);

return OK;

}

Status DestroyList(SqPointer L)

{

if(!L-base) return ErrorEXP(3); //L不存在,返回

free(L-base);

L-length = NULL;

L-listsize = NULL;

L-elemcount = NULL;

return OK;

}

Status ClearList(SqPointer L)

{

if(!L-base) return ErrorEXP(3); //L不存在,返回

L-elemcount = 0;

return OK;

}

Boolen ListEmpty(SqPointer L)

{

if(!L-base) return ErrorEXP(3); //L不存在,返回

if(L-elemcount == 0)

return TRUE;

else

return FALSE;

}

int ListElemCount(SqPointer L)

{

if(!L-base) return ErrorEXP(3); //L不存在,返回

return L-elemcount;

}

Status GetElem(SqPointer L,int i,ElemType *ret) //調(diào)用此函數(shù)需將ret指向main函數(shù)域某一ElemType變量

{

if(!L-base) return ErrorEXP(3); //L不存在,返回

if(i L-elemcount) return ErrorEXP(4); //i越界,返回

*ret = L-base[i-1]; //i 從1開(kāi)始 此種方法在main中改變*ret會(huì)直接更改鏈表中數(shù)據(jù)

return OK;

}

//重大發(fā)現(xiàn) 指針型 temp-base 普通型L.base

int LocateElem(SqPointer L,char Locatename[]) //返回的i從1開(kāi)始

{

int i=0;

ElemType *temp;

if(!L-base) return ErrorEXP(3); //L不存在,返回

while(iL-elemcount)

{

temp=(L-base[i]); //改為temp=L-base[i++];并去除下面的i++; ??

if(strcmp(temp-Name,Locatename) == 0) return i+1; //不能用temp-Name==locatename來(lái)試圖比較字符串

i++;

}

return 0;

}

Status ListInsert(SqPointer L,int i,ElemType newelem) //插入位置1=i=elemcount+1

{

ElemPointer newbase;

ElemType *temp,*flag;

if(!L-base) return ErrorEXP(3); //L不存在,返回

if(i1 || iL-elemcount + 1) return ErrorEXP(5);

if(L-elemcount == L-length)

if(IncreaseList(L)==ERROR) return ErrorEXP(6);

flag=(L-base[i-1]); //插入位置

for(temp=(L-base[L-elemcount-1]);temp=flag;temp--)

*(temp+1)=*temp;

*flag=newelem;

L-elemcount++;

return OK;

}

Status ListDelete(SqPointer L,int i,ElemType *ret) //調(diào)用此函數(shù)需將ret指向main函數(shù)域某一ElemType變量

{

ElemType *temp;

if(!L-base) return ErrorEXP(3); //L不存在,返回

if(i1 || iL-elemcount) return ErrorEXP(7);

*ret=L-base[i-1]; //刪除位置,這里先返回該值

for(temp=(L-base[i]);temp=(L-base[L-elemcount-1]);temp++)

*(temp-1)=*temp;

L-elemcount--;

return OK;

}

Status KeyInList(SqPointer L,int i)

{

ElemType temp;

time_t t;

char tmp[64];

char S;

if(!L-base) return ErrorEXP(3); //L不存在,返回

if(i1 || iL-elemcount + 1) return ErrorEXP(8);

printf("正在輸入第%d個(gè)元素的值:",i);

printf("\n編號(hào):(int)\n");

scanf("%d",temp.NO);

printf("\n姓名:(char *)\n");

scanf("%s",temp.Name);

printf("\n性別:(m or f)\n");

do{

S=getch();

if(S=='m')

temp.Sex=male;

else if(S=='f')

temp.Sex=female;

else

puts("Key in 'm' or 'f'.\n");

}while(S!='m' S!='f');

putchar(S);

printf("\n年齡:(int)\n");

scanf("%d",temp.Age);

printf("\n電話:(char *)\n");

scanf("%s",temp.Tel);

printf("\n記錄時(shí)間:\n");

t=time(0);

strftime(tmp,sizeof(tmp),"%Y/%m/%d %X %A 本年第%j天 %z",localtime(t));

puts(tmp);

strcpy(temp.Inserttime,tmp);

if(ListInsert(L,i,temp)==OK)

return OK;

else

return ErrorEXP(9);

}

ElemType ScanfElem()

{

ElemType temp;

time_t t;

char tmp[64];

char S;

printf("正在錄入元素:");

printf("\n編號(hào):(int)\n");

scanf("%d",temp.NO);

printf("\n姓名:(char *)\n");

scanf("%s",temp.Name);

printf("\n性別:(m or f)\n");

do{

S=getch();

if(S=='m')

temp.Sex=male;

else if(S=='f')

temp.Sex=female;

else

puts("Key in 'm' or 'f'.\n");

}while(S!='m' S!='f');

putchar(S);

printf("\n年齡:(int)\n");

scanf("%d",temp.Age);

printf("\n電話:(char *)\n");

scanf("%s",temp.Tel);

printf("\n記錄時(shí)間:\n");

t=time(0);

strftime(tmp,sizeof(tmp),"%Y/%m/%d %X %A 本年第%j天 %z",localtime(t));

puts(tmp);

strcpy(temp.Inserttime,tmp);

return temp;

}

Status ScanfList(SqPointer L,int i)

{

char p='c';

while(putchar('\n'),p=='c'||p=='C')

{ p='\0';

if(KeyInList(L,i++)==ERROR) return ErrorEXP(10);

printf("\nPress ESC key to exit or 'C' to continue...");

while(p!='c' p!='C' (int)p!=27)

p=getch();

}

return OK;

}

Status PrintListProperty(SqPointer L)

{

puts("SqList L Property:");

if(!L-base)

{ puts("鏈表不存在!");

return OK;}

else

puts("鏈表已初始化...\n");

printf("%d/%d BASE=%d,MemoryStatus=%d\n",L-elemcount,L-length,L-base,L-listsize);

return OK;

}

Status PrintOnScreen(SqPointer L)

{

int i;

char Stmp[7],t;

if(!L-base) return ErrorEXP(3); //L不存在,返回

puts("Push 'C' shell CLS or other key to skip.");

t=getch();

if(t=='c' || t=='C')

system("cls");

puts("數(shù)據(jù)表打印:");

for(i=0;i=L-elemcount-1;i++)

{ printf("\nElem %d st:\n",i+1);

if(L-base[i].Sex == male)

strcpy(Stmp,"male");

else if(L-base[i].Sex == female)

strcpy(Stmp,"female");

else

strcpy(Stmp,"Unknow");

printf("NO:%d\tName:%s\t\tSex:%s\tAge:%d\n\tTel:%s\n\tInsertTime:%s\n",L-base[i].NO,L-base[i].Name,Stmp,L-base[i].Age,L-base[i].Tel,L-base[i].Inserttime);

}

return OK;

}

Status PrintElem(ElemPointer elem)

{

char Stmp[7];

printf("\nPrintElem:\n");

if(elem-Sex == male)

strcpy(Stmp,"male");

else if(elem-Sex == female)

strcpy(Stmp,"female");

else

strcpy(Stmp,"Unknow");

printf("NO:%d\tName:%s\t\tSex:%s\tAge:%d\n\tTel:%s\n\tInsertTime:%s\n",elem-NO,elem-Name,Stmp,elem-Age,elem-Tel,elem-Inserttime);

return OK;

}

void main() //把以上所有函數(shù)都串了起來(lái)

{

SqList TheList;

SqPointer ListP;

ElemType mylistelem,*elemtemp;

ElemPointer mylist;

int i;

char nameT[20];

elemtemp=mylistelem; //*ret

ListP=TheList;

if(InitList(ListP)==OK) puts("InitList(TheList)==OK");

PrintListProperty(ListP);

if(ListEmpty(ListP)==TRUE) puts("ListEmpty==True");

else puts("ListEmpty==False");

ScanfList(ListP,1);

PrintListProperty(ListP);

PrintOnScreen(ListP);

printf("ListElemCount return %d.",ListElemCount(ListP));

puts("\nGetElem index? ");

scanf("%d",i);

if(GetElem(ListP,i,elemtemp)==OK) PrintElem(elemtemp);

puts("\nLocateElem name? ");

scanf("%s",nameT);

printf("LocateElem return %d.",LocateElem(ListP,nameT));

puts("\nListDelete index? ");

scanf("%d",i);

if(ListDelete(ListP,i,elemtemp)==OK) PrintElem(elemtemp);

puts("\nListInsert index? ");

scanf("%d",i);

puts("\nListInsert NEWELEM? ");

ListInsert(ListP,i,ScanfElem());

PrintListProperty(ListP);

PrintOnScreen(ListP);

if(ClearList(ListP)==OK) puts("ClearList==OK");

if(ListEmpty(ListP)==TRUE) puts("ListEmpty==True");

if(DestroyList(ListP)==OK) puts("DestroyList==OK");

getch();

}

/* 函數(shù)列表

類(lèi)型 名稱(chēng) 參數(shù) 說(shuō)明

int ErrorEXP (int i) 錯(cuò)誤描述符

Status InitList (SqPointer L) 初始化SqPointer L... 通過(guò)L返回base

Status IncreaseList (SqPointer L) L當(dāng)前滿時(shí),繼續(xù)申請(qǐng)空間

Status DestroyList (SqPointer L) 銷(xiāo)毀L

Status ClearList (SqPointer L) 把L置為空表

Boolen ListEmpty (SqPointer L) 判斷L是否為空表,是則返回TRUE

int ListElemCount (SqPointer L) 返回當(dāng)前L中記錄的元素個(gè)數(shù)

Status GetElem (SqPointer L,int i,ElemType *ret) 通過(guò)*ret返回i號(hào)元素

int LocateElem (SqPointer L,char Locatename[]) 順序查找表,根據(jù)name字段,返回首個(gè)匹配元素的i,無(wú)則返回0

Status ListInsert (SqPointer L,int i,ElemType newelem) 在L中的i號(hào)位置插入newelem元素

Status ListDelete (SqPointer L,int i,ElemType *ret) 刪除L中第i號(hào)元素,并用*ret返回該元素

Status KeyInList (SqPointer L,int i) 從鍵盤(pán)輸入單個(gè)元素并插入到i號(hào)位置

ElemType ScanfElem () 從鍵盤(pán)輸入單個(gè)元素返回一個(gè)ElemType類(lèi)型的節(jié)點(diǎn)

Status ScanfList (SqPointer L,int i) 從i號(hào)開(kāi)始遞增順序錄入元素到L,直到按'ESC'

Status PrintListProperty(SqPointer L) 打印L的屬性,打印格式為(已用空間/已申請(qǐng)空間 基址 內(nèi)存占用)

Status PrintOnScreen (SqPointer L) 打印整張L表到屏幕

Status PrintElem (ElemPointer elem) 打印單個(gè)ElemType類(lèi)型的元素

時(shí)間倉(cāng)促,所以亂了些,書(shū)上2章開(kāi)頭 動(dòng)態(tài)線性的順序表 的基本操作幾乎都寫(xiě)了

不知你說(shuō)的是不是這個(gè),mian函數(shù)比較亂,只是把所有的基本操作都串了起來(lái),你

可以根據(jù)情況改改主函數(shù)的調(diào)用過(guò)程,就會(huì)比較清楚是怎么實(shí)現(xiàn)的了。你可以按F10

進(jìn)行單部跟蹤,F(xiàn)11可以進(jìn)入調(diào)用過(guò)程,一步一步跟著程序走一遍就好了。

關(guān)于動(dòng)態(tài)鏈表的我之前寫(xiě)過(guò)一個(gè),也好象給你看過(guò),這里再附上一起發(fā)過(guò)去。文件LinkList.c

只實(shí)現(xiàn)了構(gòu)造鏈表,并打印出來(lái)的功能。

*/

一個(gè)C語(yǔ)言的問(wèn)題

locate(p,a-1,c);

if(!i)

printf("can't search\n");

else

printf("%d is %d ",c,i);

不管你找哪個(gè)數(shù)字,都是數(shù)組的長(zhǎng)度

i是前面的數(shù)值,應(yīng)該和a相等

調(diào)用函數(shù)locate并沒(méi)有改變i的數(shù)值,改變的是函數(shù)中的i數(shù)值

C語(yǔ)言高手,數(shù)據(jù)結(jié)構(gòu)高手進(jìn)!我有一些代碼不是很理解

1.我想問(wèn)一下,句子中多次用到p-next能用p.next嗎?什么情況用-什么時(shí)候用.呢

答:p-next不能用p.next替換,因?yàn)閜是一個(gè)結(jié)構(gòu)體指針,而不是一個(gè)結(jié)構(gòu)體對(duì)象。調(diào)用結(jié)構(gòu)體對(duì)象里面的一個(gè)元素,當(dāng)是一個(gè)指向結(jié)構(gòu)體指針調(diào)用的時(shí)候用-,當(dāng)是一個(gè)結(jié)構(gòu)體對(duì)象時(shí)候調(diào)用.。

2.置空表時(shí)void setnull(snode *p)為什么要*p呢?*和有什么區(qū)別?是什么意思,我能*p嗎?就定義P是指針不可以嗎?

答:你這個(gè)是c++程序吧。里面有用到引用一個(gè)概念,也就是說(shuō)snode *p等價(jià)于(snode *)p,至于為什么要用引用呢,是因?yàn)樵谥每毡聿僮髦杏行薷牡絟ead結(jié)點(diǎn),所以用了引用,當(dāng)然了,用snode **p也可以完成這種操作。

3.snode *get(snode *p,int i)這個(gè)函數(shù)為什么要*get,你可能會(huì)說(shuō)因?yàn)樽詈笫莚eturn(q),但是我想問(wèn)最后如果return回來(lái),是地址還是數(shù)值。

答:這個(gè)返回值 是一個(gè)地址。

4.locata函數(shù)里if(q==null),這句話為什么是對(duì)的,q應(yīng)該是個(gè)結(jié)構(gòu)體啊!為什么不是 q-data!=0而是直接q==null?

答:q是一個(gè)指向結(jié)構(gòu)體得指針,snode *q=p-next;p也是一個(gè)指向結(jié)構(gòu)體的指針,結(jié)構(gòu)體有兩個(gè)域,一個(gè)是數(shù)據(jù),一個(gè)是指向結(jié)構(gòu)體的指針,因此q==NULL,其實(shí)和p-next==NULL是等價(jià)的,就是為了判斷是否已經(jīng)到了鏈表的尾部,在鏈表最后一個(gè)節(jié)點(diǎn)上的next域是被置于NULL的。q-data!=0是判斷某個(gè)節(jié)點(diǎn)的數(shù)據(jù)是不是0,兩者意思不一樣的。

不知道我說(shuō)明白沒(méi)有,可以繼續(xù)討論,樓主

幫看一個(gè)入門(mén)級(jí)c語(yǔ)言編程的問(wèn)題,關(guān)于函數(shù)的位置

這是改的,主要是你的void locate(char *str1,char *str2,int m);定義問(wèn)題

#includestdio.h

#includestring.h

void main()

{

char str1[999],str2[999];

void locate(char *str1,char *str2,int m);

printf("\nPlease input the character arrays one:");

gets(str1);

printf("\nPlease input the character arrays two:\n");

gets(str2);

int m;

printf("Please input the m you want:\n");

scanf("%d",m);

locate(str1,str2,m);

}

void locate(char* str1,char *str2,int m)

{

int i;

int n;

n=strlen(str2);

for(i=0;in;i++)

{

str1[m+i]=str2[i];

}

printf("%s",str1);

}

C語(yǔ)言不太會(huì),求指點(diǎn)!

我為你增加了一個(gè)函數(shù)?mystr,與你想要的意思基本相符。

下面這個(gè)是測(cè)試圖,比如輸入?hello,?如果查找?l開(kāi)頭的,則會(huì)找到?llo?(符合你的要求)

#includestdio.h

#includestdlib.h

#includestring.h

char?*locatesubstr(char?*str1,char*str2);

char?*mystr(const?char?*s1,?const?char?*s2);

main()

{

char?str1[500],str2[500];

char?*p;

printf("Please?input?one?string:");

gets(str1);

printf("Please?input?another?string:");

gets(str2);

printf("The?result?is:\n");

p=mystr(str1,str2);

puts(p);

system("pause");

}

char?*mystr(const?char?*s1,?const?char?*s2)

{

int?n;

if?(*s2)?{

? while?(*s1)?{

? ? ? for(n?=?0;?*(s1?+?n)?==?*(s2?+?n);?n?++)?{

? ? ? ? ? if(!*(s2?+?n?+?1))

? ? ? ? ? ? ? return?(char?*)s1;

? ? ? }

? ? ? s1?++;

? }

? return?NULL;

}?else?{

? return?(char?*)s1;

}

}

char?*locatesubstr(char?*str1,char*str2)

{

int?k=0;

while(*str1!='\0')

{

? ? ? ? ? ? ? ? if(*str1==*str2)

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?k=1;

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?return(str1);

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? str1++;

}

if(k==0)

return(NULL);

}

c語(yǔ)言的單鏈表問(wèn)題,請(qǐng)問(wèn)locateLink函數(shù)有什么問(wèn)題啊?

while(p-next!=ep!=NULL)

改成

while(p!=NULL p-element!=e)


網(wǎng)站欄目:c語(yǔ)言locates函數(shù) r語(yǔ)言locator函數(shù)
本文鏈接:http://m.jcarcd.cn/article/hhsejh.html
主站蜘蛛池模板: 国产综合亚洲免费 | 99亚洲 | 成人影片免费观看 | 成人影院免 | 国产在线观看稀有 | 午夜欧美 | 国产特黄自拍大 | 精品国产v| 国产精品人 | 国产精品精彩 | 三级特黄60 | 国产手机精品一 | 情趣五月天 | 精品第一国产 | 国产精品交换 | 成人奭片免费观看 | 国产精首页 | 国产精品沙发 | 国产亚洲一区二区 | 人妖性爱影院 | 国产激情片 | 国产1区2区3区 | 欧洲日韩国产一区 | 区不卡αv | 国产精品亚洲国产在 | 91视频看看九色 | 国产剧情片视须资 | 情ss综合网 | 国产丝袜一区二 | 91看片| 国产综合色在 | 成人精品人成网站 | 成人午夜在线看 | 国产愉拍99线观看 | 国产女主播福利资源 | 国产激情久 | 精品亚洲欧美无人 | 国产18页 | 国产蝌蚪 | 欧美一级操 | 青草青草久 |