第一篇:c語言迷宮問題代碼實現
C語言迷宮問題代碼如下:
#include
#include
#define LEN sizeof(SEAT)
#define MAXSIZE 100
#define LENGTH 30
typedef struct
{
int x;//橫坐標
int y;//縱坐標
int di;//表示方向,0-3分別表示東南西北。
}SEAT;
struct StackList
{
SEAT stack[MAXSIZE];
int top;
}*Stack;
int EmptyStack(StackList*Stack)//判斷是否為空棧
{
if(Stack->top==0)
return 0;
else
return 1;
}
int Move[4][2]={{0,1},{1,0},{0,-1},{-1,0}};//分別表示向東、西、南、北需要加上的坐標
int Mase[LENGTH][LENGTH]={0};//初始化為0
int length,width;
void InitMase()//在迷宮的外圍添加一層“墻壁”(賦值為1),使得迷宮的任意一點都有四個方向
{
int i,j;
for(i=0;i { for(j=0;j Mase[i][j]=1; } for(i=0;i { for(j=0;j Mase[j][i]=1; } } void InitStack(StackList*Stack)//初始化 { Stack->top=0; return; } int PushStack(StackList*Stack,SEAT CurSeat)//進棧 { if(Stack->top==MAXSIZE-1) return false; else { Stack->stack[Stack->top].x=CurSeat.x; Stack->stack[Stack->top].y=CurSeat.y; Stack->stack[Stack->top].di=CurSeat.di; Stack->top++; return true; } } int PopStack(StackList*Stack)//出棧 { if(Stack->top==0) return false; else { Stack->top--; return true; } } int Pass(SEAT p)//判斷當前是否可行 { if(Mase[p.x][p.y]==0) { return true; } else return false; } SEAT NextSeat(SEAT CurSeat)//查找下一個點,并返回 { SEAT temp; temp.x=CurSeat.x+Move[CurSeat.di][0]; temp.y=CurSeat.y+Move[CurSeat.di][1]; return temp; } void Mark(SEAT p)//標記已經走過的點,避免重復 { Mase[p.x][p.y]=-1; } int PathWay(SEAT start,SEAT end)//找路線 { Stack=(struct StackList*)malloc(sizeof(struct StackList)); InitStack(Stack); SEAT CurSeat; CurSeat.x=start.x+1;//由于多加了一層墻壁,因此坐標的值要加1 CurSeat.y=start.y+1;// CurSeat.di=start.di;// do { if(Pass(CurSeat)) { PushStack(Stack,CurSeat); Mark(CurSeat); if(CurSeat.x==end.x+1&&CurSeat.y==end.y+1)//如果找到出口,返回{ return true; } else { int find=0; while(CurSeat.di<3&&find==0)//找下一個結點的方向 { CurSeat.di++; SEAT temp; temp=NextSeat(CurSeat); if(Mase[temp.x][temp.y]==0) { temp.di=-1; CurSeat=temp; find =1; } } } } else { if(EmptyStack(Stack))//當前的點不能走,出棧 PopStack(Stack); if(EmptyStack(Stack))//當前的點變為前一個點 { CurSeat=Stack->stack[Stack->top-1]; } while(CurSeat.di==3&&EmptyStack(Stack))////當前的點找不到下一個點,出棧 { PopStack(Stack); CurSeat=Stack->stack[Stack->top-1];//當前的點變為前一個點} if(EmptyStack(Stack)) { int find=0; while(CurSeat.di<3&&find==0)////找下一個結點的方向 { CurSeat.di++; SEAT temp; temp=NextSeat(CurSeat); if(Mase[temp.x][temp.y]==0) { temp.di=-1; CurSeat=temp; find =1; } } } } }while(EmptyStack(Stack)); return false; } void PrintStack(StackList*Stack)//輸出路線 { if(Stack->top==0) printf(“There is no route can be out of the mazen”); else { int i; for(i=0;i { if(i!=0) printf(“->(%d,%d)”,Stack->stack[i].x-1,Stack->stack[i].y-1); else printf(“(%d,%d)”,Stack->stack[i].x-1,Stack->stack[i].y-1); } } } void PrintMase()//輸出迷宮 { int i,j; for(i=1;i { for(j=1;j { if(j!=1) printf(“ %d”,Mase[i][j]); else printf(“%d”,Mase[i][j]); } printf(“n”); } } int main() { int n; SEAT start,end; printf(“Please enter the maze of the length and width:n”); scanf(“%d%d”,&length,&width); printf(“Please enter the number of the maze wall unit(0 printf(“Please enter the labyrinth of the coordinates of the wall unit(0<=row,column):n”);while(--n>=0) { int x,y; scanf(“%d%d”,&x,&y); Mase[x+1][y+1]=1; } InitMase(); PrintMase(); printf(“Please enter the coordinates entrance(0<=x<%d,0<=y<%d):n”,length,width); scanf(“%d%d”,&start.x,&start.y); start.di=-1; printf(“Please enter the coordinates exports(0<=x<%d,0<=y<%d):n”,length,width); scanf(“%d%d”,&end.x,&end.y); end.di=0; if(PathWay(start,end)) PrintStack(Stack); else printf(“There is no route can be out of the mazen”);return 0; } of the of the maze maze gamma = 0.4;%%設置初值 Q = zeros(6, 6);R = [-1-1-1-1 0-1;-1-1-1 0-1 100;-1-1-1 0-1-1;-1 0 0-1 0-1;0-1-1 0-1 100;-1 0-1-1 0 100];now = 2;seq = [];for now = 1:1:6 for i = 0:1:20 %%打亂路徑順序,選取隨機的路徑 rcolumn = R(now, :); rcolumn(rcolumn ==-1)= [];num = randperm(size(rcolumn,2)); next = find(R(now,:)== rcolumn(num(1)), 1);seq = [seq next]; Qmax = max(Q(next,:));%%更新Q函數 Q(now, next)= R(now, next)+ gamma * Qmax gamma = gamma*0.99;%%由隨即策略漸漸變為隨機策略 now = next;% for i = 0:1:5 % Qmax = max(Q(now, :)); % next = find(Q(now, :)== Qmax, 1);% seq = [seq next];% now = next;% end 大班語言活動-花園迷宮 活動目標: 1理解故事內容,猜想故事中符號含義 2大膽表述自己對符號的猜想 3愿意傾聽故事,樂意參與討論 活動準備:電子課件 故事音頻 活動重點:對故事內容中進行適合幼兒的講解 活動難點:理解故事內容基礎上對故事符號的理解和猜想 活動過程: 一 出示故事圖書,介紹書名,教師朗讀第一幅的內容,引導幼兒對故事的關注 師:小朋友們,今天啊,老師要給小朋友們介紹一位喜歡走迷宮的國王,他就是胖胖國王,胖胖國王今天要去迷宮探險,咦,迷宮門口這個花朵符號是什么意思呢? 請幼兒說完整的話:我認為這個符號是…… 師:國王在迷宮中還會看到那些符號呢?讓我們接著讀下去,一起找一找,看一看。二 教師逐頁和幼兒共同閱讀故事,講解故事內容 師:這這頁故事中,國王遇到了哪些符號?你們猜一猜它們都是什么意思呢?(教師翻頁,逐頁閱讀) 三 故事閱讀后,教師引導幼兒表述自己對故事中符號的理解和認識 師:現在我們讀完了故事,我有幾個問題想問問我們聰明的小朋友們,門口的花朵符號是什么意思? 你們怎么知道的?(請個別幼兒結合圖中信息表述理由)師:那么國王走出了迷宮了么? 國王都是按照哪些符號走出迷宮的? 在第x頁的符號是什么意思呢?(教師根據幼兒表述呈現相應符號)師:那你說說為什么你認為這個符號是這樣的意思呢? 四 教師出示國王未選擇的符號,引導幼兒用假設的方法表述對這4個符號的理解和猜想 呈現水符號 師:國王按照小朋友們所說的符號走出了迷宮,那如果國王按照剛才這些沒選的符號走會怎么樣呢?如果國王選擇這個符號的路會怎么樣?你怎么知道的? 呈現禁行和火符號 師:如果國王走了這條路,大家猜會發生什么事? 呈現苦臉符號 師:這是什么符號,國王如果走這條路會發生什么事啊? 五 請幼兒再聽一遍故事,進一步理解故事內容,了解符號在故事中的作用 活動反思: 《數據結構與算法設計》 迷宮問題實驗報告 ——實驗二 專業:物聯網工程 班級:物聯網1班 學號:15180118 姓名:劉沛航 一、實驗目的 本程序是利用非遞歸的方法求出一條走出迷宮的路徑,并將路徑輸出。首先由用戶輸入一組二維數組來組成迷宮,確認后程序自動運行,當迷宮有完整路徑可以通過時,以0和1所組成的迷宮形式輸出,標記所走過的路徑結束程序;當迷宮無路徑時,提示輸入錯誤結束程序。 二、實驗內容 用一個m*m長方陣表示迷宮,0和1分別表示迷宮中的通路和障礙。設計一個程序對于任意設定的迷宮,求出一條從入口到出口的通路,或得出沒有通路的結論。 三、程序設計 1、概要設計 (1)設定棧的抽象數據類型定義 ADT Stack{ 數據對象:D={ai|ai屬于CharSet,i=1、2…n,n>=0} 數據關系:R={ 操作結果:構造一個空棧 Push(&S,e) 初始條件:棧已經存在 操作結果:將e所指向的數據加入到棧s中 Pop(&S,&e) 初始條件:棧已經存在 操作結果:若棧不為空,用e返回棧頂元素,并刪除棧頂元素 Getpop(&S,&e) 初始條件:棧已經存在 操作結果:若棧不為空,用e返回棧頂元 StackEmpty(&S) 初始條件:棧已經存在 操作結果:判斷棧是否為空。若棧為空,返回1,否則返回0 Destroy(&S) 初始條件:棧已經存在 操作結果:銷毀棧s }ADT Stack (2)設定迷宮的抽象數據類型定義 ADT yanshu{ 數據對象:D={ai,j|ai,j屬于{‘ ’、‘*’、‘@’、‘#’},0<=i<=M,0<=j<=N} 數據關系:R={ROW,COL} ROW={ InitMaze(MazeType &maze, int a[][COL], int row, int col){ 初始條件:二維數組int a[][COL],已經存在,其中第1至第m-1行,每行自第1到第n-1列的元素已經值,并以值0表示障礙,值1表示通路。 操作結果:構造迷宮的整形數組,以空白表示通路,字符‘0’表示障礙 在迷宮四周加上一圈障礙 MazePath(&maze){ 初始條件:迷宮maze已被賦值 操作結果:若迷宮maze中存在一條通路,則按如下規定改變maze的狀態;以字符‘*’表示路徑上的位置。字符‘@’表示‘死胡同’;否則迷宮的狀態不變 } PrintMaze(M){ 初始條件:迷宮M已存在 操作結果:以字符形式輸出迷宮 } }ADTmaze (3)本程序包括三個模塊 a、主程序模塊 void main(){ 初始化; 構造迷宮; 迷宮求解; 迷宮輸出; } b、棧模塊——實現棧的抽象數據類型 c、迷宮模塊——實現迷宮的抽象數據類型 2、詳細設計 (1)坐標位置類型: typedef struct{ int row;//迷宮中的行 int col;//......的列 }PosType;//坐標 (2)迷宮類型: typedef struct{ int m,n;int arr[RANGE][RANGE];}MazeType;//迷宮類型 void InitMaze(MazeType &maze, int a[][COL], int row, int col)//設置迷宮的初值,包括邊緣一圈的值 Bool MazePath(MazeType &maze,PosType start, PosType end)//求解迷宮maze中,從入口start到出口end的一條路徑 //若存在,則返回true,否則返回false Void PrintMaze(MazeType maze)//將迷宮打印出來 (3)棧類型: typedef struct{ int step;//當前位置在路徑上的“序號” PosType seat;//當前的坐標位置 DirectiveType di;//往下一個坐標位置的方向 }SElemType;//棧的元素類型 typedef struct{ SElemType *base;SElemType *top;int stacksize;}SqStack;棧的基本操作設置如下: Void InitStack(SqStack & S) //初始化,設S為空棧(S.top=NUL)Void DestroyStack(Stack &S)//銷毀棧S,并釋放空間 Void ClearStack(SqStack & S)//將棧S清空 Int StackLength(SqStack &S)//返回棧S的長度 Status StackEmpty(SqStack &S)?、若S為空棧(S.top==NULL),則返回TRUE,否則返回FALSE Statue GetTop(SqStack &S,SElemType e) //r若棧S不空,則以e待會棧頂元素并返回TRUE,否則返回FALSE Statue Pop(SqStack&S,SElemType e)//若分配空間成功,則在S的棧頂插入新的棧頂元素s并返回TRUE //否則棧不變,并返回FALSE Statue Push(SqStack&S,SElemType &e)//若分配空間程控,則刪除棧頂并以e帶回其值,則返回TRUE //否則返回FALSE Void StackTraverse(SqStack &S,Status)(*Visit)(SElemType e))//從棧頂依次對S中的每個節點調用函數Visit 4求迷宮路徑的偽碼算法: Status MazePath(MazeType &maze,PosType start, PosType end){ //求解迷宮maze中,從入口start到出口end的一條路徑 InitStack(s);PosType curpos = start;int curstep = 1;//探索第一部 do{ if(Pass(maze,curpos)){ //如果當前位置可以通過,即是未曾走到的通道塊 FootPrint(maze,curpos);//留下足跡 e = CreateSElem(curstep,curpos,1);//創建元素 Push(s,e);if(PosEquare(curpos,end))return TRUE;curpos =NextPos(curpos,1);//獲得下一節點:當前位置的東鄰 curstep++;//探索下一步 }else{ //當前位置不能通過 if(!StackEmpty(s)){ Pop(s,e);while(e.di==4 &&!StackEmpty(s)){ MarkPrint(maze,e.seat);Pop(s,e);//留下不能通過的標記,并退回步 } if(e.di<4){ e.di++;Push(s,e);//換一個方向探索 curpos = NextPos(e.seat,e.di);//設定當前位置是該方向上的相塊 }//if }//if }//else }while(!StackEmpty(s));return FALSE;} //MazePath 四、程序調試分析 1.首先呢,想自己讀入數據的,回來發現那樣,很麻煩,所以還是事先定義一個迷宮。 2.棧的元素類型 一開始有點迷惑,后來就解決了 3.本題中三個主要算法;InitMaze,MazePath和PrintMaze的時間復雜度均為O(m*n)本題的空間復雜度也是O(m*n) 五、用戶使用說明 1.本程序運行在windows系列的操作系統下,執行文件為:Maze_Test.exe。 六、程序運行結果 1.建立迷宮: 2.通過1功能建立8*8的迷宮后,通過2功能繼續建立迷宮內部: 通過建立自己設定單元數目建立迷宮內墻。3.通過3功能觀察已建立的迷宮結構: 4.通過4功能確立迷宮起點和終點: (此處像我們隨機選擇4,4和2,7分別為起點終點) 5.執行5功能,判斷是否有路徑走出迷宮: 這種情況無法走出迷宮。 我們再次觀察圖像設4,4和1,6分別為起點終點,再運行5功能。 觀察到可以成功解開迷宮步數從1依次開始。 七、程序清單 #include // 列值 #define MAXLENGTH 25 // 設迷宮的最大行列為25 typedef int MazeType[MAXLENGTH][MAXLENGTH];// 迷宮數組[行][列] typedef struct // 棧的元素類型 { int ord;// 通道塊在路徑上的"序號" PosType seat;// 通道塊在迷宮中的"坐標位置" int di;// 從此通道塊走向下一通道塊的"方向"(0~3表示東~北)}SElemType; // 全局變量 MazeType m;// 迷宮數組 int curstep=1;// 當前足跡,初值為1 #define STACK_INIT_SIZE 10 // 存儲空間初始分配量 #define STACKINCREMENT 2 // 存儲空間分配增量 // 棧的順序存儲表示 typedef struct SqStack { SElemType *base;// 在棧構造之前和銷毀之后,base的值為NULL SElemType *top; int stacksize; // 構造一個空棧S int InitStack(SqStack *S){ // 為棧底分配一個指定大小的存儲空間 (*S).base =(SElemType *)malloc(STACK_INIT_SIZE*sizeof(SElemType));if(!(*S).base) (*S).top =(*S).base; return 1; // 棧底與棧頂相同表示一個空棧 (*S).stacksize = STACK_INIT_SIZE;exit(0);}SqStack;// 順序棧 // 棧頂指針 // 當前已分配的存儲空間,以元素為單位 } // 若棧S為空棧(棧頂與棧底相同的),則返回1,否則返回0。int StackEmpty(SqStack S){ if(S.top == S.base) else } // 插入元素e為新的棧頂元素。int Push(SqStack *S, SElemType e){ if((*S).top-(*S).base >=(*S).stacksize)// 棧滿,追加存儲空間 { } *((*S).top)++=e;return 1;} // 若棧不空,則刪除S的棧頂元素,用e返回其值,并返回1;否則返回0。int Pop(SqStack *S,SElemType *e){ if((*S).top ==(*S).base) 左 return 1;} // 定義墻元素值為0,可通過路徑為1,不能通過路徑為-1,通過路徑為足跡 // 當迷宮m的b點的序號為1(可通過路徑),return 1;否則,return 0。int Pass(PosType b){ if(m[b.x][b.y]==1) else return 0;return 1;return 0;*e = *--(*S).top; // 這個等式的++ * 優先級相同,但是它們的運算方式,是自右向 (*S).base =(SElemType *)realloc((*S).base ,(*S).top =(*S).base+(*S).stacksize;(*S).stacksize += STACKINCREMENT;((*S).stacksize + STACKINCREMENT)* sizeof(SElemType));exit(0);if(!(*S).base)return 0;return 1;} void FootPrint(PosType a) // 使迷宮m的a點的序號變為足跡(curstep),表示經過 { m[a.x][a.y]=curstep;} // 根據當前位置及移動方向,返回下一位置 PosType NextPos(PosType c,int di){ PosType direc[4]={{0,1},{1,0},{0,-1},{-1,0}};// {行增量,列增量} // 移動方向,依次為東南西北 c.x+=direc[di].x;c.y+=direc[di].y;return c;} // 使迷宮m的b點的序號變為-1(不能通過的路徑)void MarkPrint(PosType b){ m[b.x][b.y]=-1;} // 若迷宮maze中存在從入口start到出口end的通道,則求得一條 // 存放在棧中(從棧底到棧頂),并返回1;否則返回0 int MazePath(PosType start,PosType end){ SqStack S;PosType curpos;SElemType e; InitStack(&S);curpos=start;do { if(Pass(curpos)){// 當前位置可以通過,即是未曾走到過的通道塊 FootPrint(curpos);// 留下足跡 e.ord=curstep;e.seat.x=curpos.x;e.seat.y=curpos.y;e.di=0;Push(&S,e);// 入棧當前位置及狀態 curstep++;// 足跡加1 if(curpos.x==end.x&&curpos.y==end.y)// 到達終點(出口) } else return 1;curpos=NextPos(curpos,e.di);{// 當前位置不能通過 } if(!StackEmpty(S)){ } Pop(&S,&e);// 退棧到前一位置 curstep--;while(e.di==3&&!StackEmpty(S))// 前一位置處于最后一個方向(北){ } if(e.di<3)// 沒到最后一個方向(北){ } e.di++;// 換下一個方向探索 Push(&S,e);curstep++;// 設定當前位置是該新方向上的相鄰塊 curpos=NextPos(e.seat,e.di); MarkPrint(e.seat);// 留下不能通過的標記(-1)Pop(&S,&e);// 退回一步 curstep--;}while(!StackEmpty(S));return 0;} // 輸出迷宮的結構 void Print(int x,int y){ int i,j; for(i=0;i } } void main(){ PosType begin,end;int i,j,x,y,x1,y1,n,k;for(j=0;j //清屏函數 printf(“***************************************************nnn”);printf(“ 1請輸入迷宮的行數,列數n”);printf(“ 2請輸入迷宮內墻單元數n”);printf(“ 3迷宮結構如下n”);printf(“ 4輸入迷宮的起點和終點n”);printf(“ 5輸出結果n”);printf(“ 0退出n”);printf(“nn請選擇 ”);scanf(“%d”,&n);switch(n){ case 1:{ printf(“請輸入迷宮的行數,列數(包括外墻):(空格隔開)”); scanf(“%d%d”, &x, &y); for(j=1;j { for(i=1;i for(j=1;j // 迷宮左邊列的周邊即左邊墻 m[j][y-1]=0;// 迷宮右邊列的周邊即右邊墻 for(i=0;i // 迷宮上面行的周邊即上邊墻 m[x-1][i]=0;// 迷宮下面行的周邊即下邊墻 物 聯 網 班 -15180118-劉沛 航 } }break; case 2: {printf(“請輸入迷宮內墻單元數:”); scanf(“%d”,&j); printf(“請依次輸入迷宮內墻每個單元的行數,列數:(空格隔開)n”); for(i=1;i<=j;i++) { scanf(“%d%d”,&x1,&y1); } m[x1][y1]=0; }break; case 3:{ Print(x,y);printf(“劉沛航建立的迷宮,定義墻元素值為0,可通過路徑為1,輸入0退出”);scanf(“%d”,&k);}break; case 4:{ printf(“請輸入起點的行數,列數:(空格隔開)”); scanf(“%d%d”,&begin.x,&begin.y); printf(“請輸入終點的行數,列數:(空格隔開)”); scanf(“%d%d”,&end.x,&end.y);}break; case 5:{ if(MazePath(begin,end))// 求得一條通路 { } else printf(“此迷宮沒有從入口到出口的路徑,謝謝使用劉沛航的程序n”);printf(“輸入0退出”);scanf(“%d”,&k);}break;} }while(n!=0);} printf(“此迷宮從入口到出口的一條路徑如下,謝謝使用劉沛航的程序:n”);Print(x,y);// 輸出此通路 #include “stdio.h” #include void main(){ int n=0;struct course *head=NULL;void insert(struct course **head,struct course *cou);void Print(struct course **head,int *n);void Modify(struct course **head,int *n);void Require(struct course **head);void Creat(struct course **head,int *n);void Delete(struct course **head,int *n);void Fun(struct course **head,int *n); Fun(&head,&n);} void insert(struct course **head,struct course *cou){ struct course *p0,*p1,*p2;p2=p1=*head;p0=cou;if(*head){ while((p0->semester>p1->semester)&&(p1->next)) { p2=p1; p1=p1->next; } if(p0->semester semester) { if(*head==p1)*head=p0; else p2->next=p0; p0->next=p1;} else { if(p0->semester==p1->semester){ while((p0->cID>p1->cID)&&(p1->next)&&(p0->semester==p1->semester)) { } if(p0->semester!=p1->semester){ } else { if(p0->cID<=p1->cID){ if(*head==p1)*head=p0;else p2->next=p0;p2=p1;p1=p1->next;p2->next=p0;p0->next=p1; p0->next=p1; } else {p1->next=p0;p0->next=NULL;} } } else {p1->next=p0;p0->next=NULL;} } } else { *head=p0; p0->next=NULL;} } void Print(struct course **head,int *n){ struct course *p;p=*head;if(*head){ if(*n==1)printf(“nThis %d record is:n”,*n); else printf(“nThese %d records are:n”,*n); printf(“semester cID name creditn”); do { printf(“%-10d%-10d%-18s%-12.1f n”,p->semester,p->cID,p->name,p->credit); p=p->next; }while(p!=NULL);} else printf(“nList null!n”);} void Modify(struct course **head,int *n){ struct course *p,*p2;int cID;if(*head){ Print(head,n);while(1){ printf(“nPlease input the cID which you want to modify:”); scanf(“%d”,&cID);p2=p=*head;while(p->next&&(cID!=p->cID)){ p2=p; p=p->next;} if(cID==p->cID){ printf(“Please input the new cID(1~60):”); scanf(“%d”,&p->cID); while(p->cID<0||p->cID>60) { printf(“nError!”); printf(“nPlease input the new cID(1~60):”); scanf(“%d”,&p->cID); } printf(“Please input the new semester(1~8):”); scanf(“%d”,&p->semester);while(p->semester<0||p->semester>8) { printf(“nError!”); printf(“nPlease input the new semester(1~8):”); scanf(“%d”,&p->semester); } printf(“Please input the new credit:”); scanf(“%f”,&p->credit); printf(“Please input the new name:”); scanf(“%s”,p->name); if(p==*head)*head=p->next; else p2->next=p->next; insert(head,p); break; } else printf(“%d not been found!n”,cID); } } else {printf(“nList null!n”);} } void Require(struct course **head){ struct course *p;float sum=0;int sem,i=0;printf(“nPlease input the semester which is required:”); scanf(“%d”,&sem);p=*head;while(p){ if(sem==p->semester) { i++;if(i==1)printf(“nsemester cID name creditn”);printf(“%-10d%-10d%-18s%-12.1f n”,p->semester,p->cID,p->name,p->credit); sum=sum+p->credit; } p=p->next;} printf(“The sum of credit in this term is:%.1fn”,sum);} void Creat(struct course **head,int *n){ struct course *p1;while(1){ p1=(struct course *)malloc(LEN); printf(“Please input the cID(1~60):”); scanf(“%d”,&p1->cID); while(p1->cID<0||p1->cID>60) { printf(“nError!”); printf(“nPlease input the cID(1~60):”); scanf(“%d”,&p1->cID); } if(p1->cID==0)break; printf(“Please input the semester(1~8):”); scanf(“%d”,&p1->semester); while(p1->semester<0||p1->semester>8) { printf(“nError!”); printf(“nPlease input the semester(1~8):”);scanf(“%d”,&p1->semester); } } } printf(“Please input the credit:”);scanf(“%f”,&p1->credit);printf(“Please input the name:”);scanf(“%s”,p1->name);insert(head,p1);*n=*n+1;printf(“nYou can continue until the cID is ”0“!n”);Print(head,n);void Delete(struct course **head,int *n){ struct course *p1,*p2;int cID;Print(head,n);if(*head){ printf(“Please input the cID of the course which you want to delete:”);scanf(“%d”,&cID);p1=*head; while(cID!=p1->cID&&p1->next!=NULL) { p2=p1; p1=p1->next; } if(cID==p1->cID) { if(p1==*head)*head=p1->next; else p2->next=p1->next; printf(“Have delete cID:%dn”,cID); *n=*n-1; } else printf(“%d not been found!n”,cID);} } void Fun(struct course **head,int *n){ char num; while(1) { system(“cls”); puts(“**************** Main Menu ******************”); puts(“* 1.Add Records 2.Print Records *”); puts(“* 3.Delete Records 4.Modify Records *”); puts(“* 5.Require Records 6.Exit *”); printf(“Please input your choice: ”); scanf(“%d”,&num); switch(num) { case 1:Creat(head,n);break; case 2:Print(head,n);break; case 3:Delete(head,n);break; case 4:Modify(head,n);break; case 5:Require(head);break;case 6:exit(0);break; default: break; } printf(“nPress ”Enter“ to continue!”);getchar();getchar(); } }第二篇:Q學習走迷宮MATLAB代碼
第三篇:大班語言-花園迷宮
第四篇:數據結構迷宮問題實驗報告
第五篇:C語言課程設計代碼