第一篇:計算機軟件技術(shù)基礎(chǔ)實驗報告
計算機軟件技術(shù)基礎(chǔ)
實驗報告
自動化0901班
郝萬福
學(xué)號:20092395 實驗1:線性表的排序與查找
目的:
掌握數(shù)據(jù)結(jié)構(gòu)的基本概念、線性表的基本操作以及查找和排序方法的設(shè)計。內(nèi)容:
鍵盤輸入一組無序數(shù)據(jù),添加到線性表中; 排序線性表并輸出排序結(jié)果;
鍵盤輸入一個數(shù),并插入到排好序的線性表中(要求插入后的表仍為有序表),輸出結(jié)果;
鍵盤輸入一個數(shù),并從線性表中刪除相應(yīng)的數(shù)據(jù),輸出結(jié)果。要求:
程序清單;
運行過程及運行結(jié)果。
實驗代碼:
/*
*/
#include “stdafx.h” #include “iostream” #include
// 程序?qū)崿F(xiàn)有各種方法,這里給出一個實例。
// 定義一個線性表
const int nMaxSize = 15;// 最大值 int nLen = 0;
// 定義操作 void LSort();void LOut();void LInsert(int n);void LDelete(int n);
int main(){
// 輸入數(shù)據(jù)并放入線性表中
printf(“Please input datan”);// std::cout << “Please input datan”;int nIn = 0;
// 表中元素個數(shù)
int nLinearList[nMaxSize];班級:自動化 0901 班 姓名:郝萬福 學(xué)號:20092395
編譯環(huán)境: Visual Studio 2011 Windows 7 x86-64 旗艦版
} for(int i = 0;i <= 9;i++){
}
LSort();// 排序線性表 LOut();// 輸出結(jié)果 scanf(“%d”,&nIn);nLen++;
//
std::cin >> nIn;
nLinearList[i] = nIn;printf(“Please input a data to insert n”);scanf(“%d”,&nIn);LInsert(nIn);LOut();printf(“Please input a data to delete n”);scanf(“%d”,&nIn);LDelete(nIn);LOut();char chTmp;printf(“Please input a char to finish this program.”);chTmp = getch();return 0;// 輸入一個數(shù)字,并從線性表中刪除 // 輸入一個數(shù)字,并插入到線性表中
void LSort(){
}
void LOut(){
// 冒泡排序,由大到小
for(int j=0;j<=10;j++){
} for(int i=0;i<11-j;i++)
if(nLinearList[i] int temp=nLinearList[i];nLinearList[i]=nLinearList[i+1];nLinearList[i+1]=temp;} printf(“n”);for(int i = 0;i < nLen;i++){ } } printf(“%d, ”, nLinearList[i]);printf(“n”);void LInsert(int n){ nLen++;nLinearList[nLen] = n;for(int k=0;k<=nLen;k++){for(int l=0;l 實驗結(jié)果: 實驗2:棧與隊列的應(yīng)用 目的: 掌握棧與隊列的基本概念、基本操作及設(shè)計與應(yīng)用。內(nèi)容: 鍵盤輸入算數(shù)表達式,并放入隊列當(dāng)中; 應(yīng)用棧的概念設(shè)計表達式求值算法; 輸出表達式求值結(jié)果; 要求: 程序清單; 運行過程及運行結(jié)果。 要求: 實現(xiàn)實驗內(nèi)容的SQL語句,以及輸出結(jié)果 為檢驗實驗內(nèi)容的有效性而執(zhí)行的SQL語句,例如向數(shù)據(jù)表中插入數(shù)據(jù); 檢驗運行結(jié)果(例如插入、刪除)的SQL語句,以及輸出的結(jié)果。 實驗代碼: /* */ #include “stdafx.h” #include const int MAX_LEN = 10; // 定義一個隊列的結(jié)構(gòu) struct QUEUE { int nMaxSize;int nCount;int nFront;// 最大值 // 個數(shù) // 頭 // 字符串的長度 const int MAX_SIZE = 30;// ?;蜿牭淖畲笤貍€數(shù) 班級:自動化 0901 班 姓名:郝萬福 學(xué)號:20092395 編譯環(huán)境: Visual Studio 2011 Windows 7 x86-64 旗艦版 int nRear;// 尾 char szQueue[MAX_SIZE][MAX_LEN];} QQ;//定義一個棧的結(jié)構(gòu) struct STACK { // 隊列的操作 void InitQueue(QUEUE *q,int nMaxSize){ } void InQueue(QUEUE *q, char *pItem){ } void OutQueue(QUEUE *q, char *pItem){ if(q->nCount == 0){ } q->nCount--;int i;printf(“隊列已空n”);getch();return 0;if(q->nMaxSize == q->nCount){ } q->nCount++;int i;for(i=0;i<10;i++){ } q->nFront ++;return;q->szQueue[q->nFront][i]= pItem[i];printf(“隊列已滿n”);getch();return 0;q->nMaxSize=nMaxSize;q->nCount=0;q->nFront=0;q->nRear=0;int nMaxSize;int nTop;// 最大值 // 棧頂 char szStack[MAX_SIZE][MAX_LEN];} ST; } for(i=0;i<10;i++){ } q->nRear ++;return;pItem[i] = q->szQueue[q->nRear][i];//棧的操作 void InitStack(STACK *s,int nMaxSize){ } void PushStack(STACK *s, char *pItem){ } void PopStack(STACK *s, char *pItem){ if(s->nTop == 0){ } printf(“堆棧已空n”);getch();return 0;if(s->nTop == s->nMaxSize-1){ } for(int i=0;i<10;i++){ } s->nTop++;s->szStack[s->nTop][i]= pItem[i];printf(“堆棧已滿n”);getch();return 0;s->nMaxSize=nMaxSize;s->nTop=0;// 棧頂 // 最大值 s->nTop--;for(int i=0;i<10;i++){ } void GetTopStack(STACK *s, char *pItem){ pItem[i] = s->szStack[s->nTop][i];} } for(int i=0;i<10;i++)pItem[i] = s->szStack[s->nTop-1][i];{ } int Priority(char *op);式的值 int main(){ int i=0; char c,temp[10]; // 聲明一個隊列 QUEUE qq; // 聲明OS棧和NS棧 STACK ns,os; // 獲得操作符的優(yōu)先級 // 計算表達void Compute(char *num1, char *num2, char *op, char *chResult); InitQueue(&qq,MAX_SIZE);InitStack(&ns,MAX_SIZE);char x[MAX_LEN];char op[MAX_LEN]; // 定義掃描的表達式 // 棧頂運算符 // 運算結(jié)果 InitStack(&os,MAX_SIZE);char num1[MAX_LEN], num2[MAX_LEN];// 兩個操作數(shù) char chResult[MAX_LEN];printf(“Input expression please:n”);while((c=getchar())!='n'){ InQueue(&qq,temp);temp[0]=c;InQueue(&qq,temp);i=0; if(isdigit(c)){ } else { for(;i<10;i++){ } temp[i]='