資源簡介
學數據結構時的作業,也發上來吧,有需要的同學可以看看.里面大多數都是可以運行的,圖里有一兩個不能運行,但是稍修改一下就可以啦.
代碼片段和文件信息
#include
#include
#include
#define?MAX?100
#define?TURE?1
#define?FALSE?0
struct?LString
{
char?*?SDate;
int?StrLen;
LString?*?pNext;
};
struct?LStringTop
{
LString?*?Top;
};
void?InitString(LStringTop?*?ls)
{
if((ls->Top=(LString?*)malloc(sizeof(LString)))==NULL)
{
printf(“memory?false\n“);
exit(1);
}
ls->Top->SDate=NULL;
ls->Top->StrLen=0;
ls->Top->pNext=NULL;
}
void?InitArray(char?*?c)
{
int?i;
for(i=0;i c[i]=‘\0‘;
}
int?Insert(LStringTop?*?lschar?*?cd)
{
LString?*?NewAdd=NULL;
if((NewAdd=(LString?*)malloc(sizeof(LString)))==NULL)
{
printf(“memory?false_1\n“);
exit(1);
}
int?i=0l=0;
????while(cd[i]!=‘\0‘)
i++;
if(i==0)
{
printf(“the?string?is?empty\n“);
return?FALSE;
}
????if((NewAdd->SDate=(char?*)malloc(i*sizeof(char)))==NULL)
{
printf(“memory?false_2\n“);
exit(1);
}
for(l=0;l NewAdd->SDate[l]=cd[l];
NewAdd->StrLen=i;
????NewAdd->pNext=ls->Top;
ls->Top=NewAdd;
//ls=NewAdd;?????????????????//ls是一個常量指針,這種賦值是錯誤的,不能改變ls的指向或它里面的值;
return?TURE;
}
void?DisplayString(LStringTop?*?ls)
{
LString?*?NewAdd=ls->Top;
printf(“now?output?the?charstrings:\n“);
while(NewAdd->pNext!=NULL)
{
printf(“%s\n“NewAdd->SDate);
printf(“total:%d\n“NewAdd->StrLen);
????????NewAdd=NewAdd->pNext;
}
}
void?DestroyString(LStringTop?*?ls)
{
LString?*?NewAdd=ls->Top->pNext;
while(ls->Top->pNext!=NULL)
{
free?(ls->Top->SDate);
free?(ls->Top);??????????????????//要在釋放內存之前把內存中的內容取出,否則將造成錯誤;
ls->Top=NewAdd;
NewAdd=ls->Top->pNext;
}
free?(ls->Top);
}
void?main()
{
LStringTop??top;??????????????????//&lstring是常量指針,不能把它指向別的位置;在使用指針傳遞參數,并期望使用指針改變原來的值時,一定要注意,以下情況,int?*?i;fuction(i)這種情況下,并不能得到期望結果;
char?array[MAX]c=‘y‘;
InitArray(array);
????InitString(&top);
while(c==‘y‘)
{
printf(“input?a?charstring\n“);
scanf(“%s“array);
Insert(&toparray);
InitArray(array);
printf(“continue?y/n\n“);
scanf(“?%c“&c);
}
DisplayString(&top);
DestroyString(&top);
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????2234??2007-04-09?13:51??數據結構\串\動態串\c2.cpp
?????文件???????3353??2007-04-09?10:27??數據結構\串\動態串\c2.dsp
?????文件????????529??2007-04-09?12:42??數據結構\串\動態串\c2.dsw
?????文件??????41984??2007-07-27?16:57??數據結構\串\動態串\c2.ncb
?????文件??????53760??2007-07-27?16:57??數據結構\串\動態串\c2.opt
?????文件????????728??2007-04-09?13:51??數據結構\串\動態串\c2.plg
?????文件?????167981??2007-04-09?13:51??數據結構\串\動態串\Debug\c2.exe
?????文件???????7709??2007-04-09?13:51??數據結構\串\動態串\Debug\c2.obj
?????文件?????427008??2007-04-09?13:51??數據結構\串\動態串\Debug\c2.pdb
?????文件??????53248??2007-04-09?13:51??數據結構\串\動態串\Debug\vc60.pdb
?????文件????????707??2007-04-09?13:59??數據結構\串\動態串\readme.txt
?????文件???????1508??2007-04-08?22:13??數據結構\串\靜態串\c1.cpp
?????文件???????3353??2008-05-02?18:38??數據結構\串\靜態串\c1.dsp
?????文件????????529??2008-05-02?18:38??數據結構\串\靜態串\c1.dsw
?????文件??????41984??2008-05-02?18:38??數據結構\串\靜態串\c1.ncb
?????文件??????48640??2008-05-02?18:38??數據結構\串\靜態串\c1.opt
?????文件????????726??2008-05-02?18:38??數據結構\串\靜態串\c1.plg
?????文件???????1858??2007-04-09?10:26??數據結構\串\靜態串\c2.cpp
?????文件???????3353??2007-04-08?23:09??數據結構\串\靜態串\c2.dsp
?????文件????????529??2007-04-08?23:23??數據結構\串\靜態串\c2.dsw
?????文件??????41984??2007-04-09?10:27??數據結構\串\靜態串\c2.ncb
?????文件??????53760??2007-04-09?10:27??數據結構\串\靜態串\c2.opt
?????文件????????726??2007-04-09?10:26??數據結構\串\靜態串\c2.plg
?????文件?????163891??2008-05-02?18:38??數據結構\串\靜態串\Debug\c1.exe
?????文件???????5435??2008-05-02?18:38??數據結構\串\靜態串\Debug\c1.obj
?????文件?????418816??2008-05-02?18:37??數據結構\串\靜態串\Debug\c1.pdb
?????文件?????163884??2007-04-09?10:26??數據結構\串\靜態串\Debug\c2.exe
?????文件???????7001??2007-04-09?10:26??數據結構\串\靜態串\Debug\c2.obj
?????文件?????427008??2007-04-09?10:26??數據結構\串\靜態串\Debug\c2.pdb
?????文件??????53248??2008-05-02?18:37??數據結構\串\靜態串\Debug\vc60.pdb
............此處省略571個文件信息
- 上一篇:mfc繪制二維坐標系和波形圖
- 下一篇:C++光線跟蹤
評論
共有 條評論