思考再三,我這次嘗試改成two pass的方式做,這樣就不會有需要動態增長的陣列了。
但是不知道會拉長多少處理時間。
但是鏈表怎套上嵌套結構陣列上,還是沒頭緒。
同一題材用不一樣方式作,邊試邊學。
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <windows.h> #include <time.h> #include <io.h> #define Max_Size 256 #define FOREGROUND_WHITE (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY) int FlowCount=100,SubCount=50,SiteNum=4,PinCount=20; struct PinInfo { char PinName[Max_Size]; char PinPoF[1]; float LO_LIMIT; float HI_LIMIT; float LO_SPEC; float HI_SPEC; float PinResult; char UNITS[1]; }; struct BIN { short int SoftBin; short int HwardBin; }; struct IC { PinInfo *ICData; char ItemType[1]; int PinNum; int PinTestTime; int ICNumber; short int X; short int Y; }; struct Site { IC *SiteData; int SiteCount; BIN *SiteBin; char SubTestName[Max_Size]; }; struct SubTest { Site *SubTestData; int SubTestNumber; }; struct Flow { SubTest *FlowData; int FlowNumber; }; void InitPinInfoStruct(PinInfo *Pin) { Pin->HI_LIMIT = 0.0 ; Pin->HI_SPEC = 0.0 ; Pin->LO_LIMIT = 0.0 ; Pin->LO_SPEC = 0.0 ; memset(Pin->PinName,0,sizeof(Pin->PinName)); memset(Pin->PinPoF,0,sizeof(Pin->PinPoF)); Pin->PinResult = 0.0 ; memset(Pin->UNITS,0,sizeof(Pin->UNITS)); } void InitICStruct(IC *ic) { ic->ICData = new PinInfo[Max_Size]; InitPinInfoStruct(ic->ICData); memset(ic->ItemType,0,sizeof(ic->ItemType)); ic->ICNumber = 0 ; ic->PinNum = 0 ; ic->PinTestTime = 0 ; ic->X = 0 ; ic->Y = 0 ; } void InitBINStruct(BIN *bin) { bin->HwardBin = 0 ; bin->SoftBin = 0 ; } void InitSiteStruct(Site *SN) { SN->SiteData = new IC[Max_Size]; InitICStruct(SN->SiteData); SN->SiteBin = new BIN[Max_Size]; InitBINStruct(SN->SiteBin); SN->SiteCount = 0 ; memset(SN->SubTestName,0,sizeof(SN->SubTestName)); } void InitSubTestStruct(SubTest *SubT) { SubT->SubTestData = new Site[SiteNum]; InitSiteStruct(SubT->SubTestData); SubT->SubTestNumber = 0 ; } void InitFlowStruct(Flow *Project) { Project->FlowData = new SubTest[SubCount]; InitSubTestStruct(Project->FlowData); Project->FlowNumber = 0 ; } void main(int argc, char* argv[]) { Flow *ProjectD = new Flow[FlowCount]; InitFlowStruct(ProjectD); }