文档介绍:
实验一代码:#include"iostream"#include//定义一个线性表constintnMaxSize=15; //最大值intnLen=0; //表中元素个数intnLinearList[nMaxSize];//定义操作voidLSort();voidLOut();voidLInsert(intn);voidLDelete(intn);voidmain(){//输入数据并放入线性表中printf("Pleaseinputdata\n"); //std::cout<>nIn;nLinearList[i]=nIn;nLen++;}LSort(); //排序线性表LOut(); //输出结果printf("Pleaseinputadatatoinsert\n");scanf("%d",&nIn);LInsert(nIn); //输入一个数字,并插入到线性表中LOut();LSort();printf("sorted:\n");LOut(); while(1){printf("Pleaseinputanumberofdatatodelete\n");scanf("%d",&nIn);if(nIn>nLen)printf("numbermustlessthan%d\n",nLen);elsebreak;}LDelete(nIn); //输入一个数字,并从线性表中删除LOut(); charchTmp;printf("Pleaseinputachartofinishthisprogram.");chTmp=getch();}voidLSort() //冒泡排序,由大到小{inti,j,temp;for(j=0;jnLen)printf("placenumbermustlessthan%d\n",nLen);elsebreak;}for(i=nLen;i>=j;--i)nLinearList[i]=nLinearList[i-1];nLinearList[j-1]=k;nLen++;}voidLDelete(intm){inti;for(i=m;i<=nLen;++i)nLinearList[i-1]=nLinearList[i];nLen--;}实验二代码:#include#include#include#includeconstintMAX_LEN=10; //字符串的长度constintMAX_SIZE=30; //栈或队的最大元素个数//定义一个队列的结构structQUEUE{intnMaxSize; //最大值intnCount; //个数intnFront; //头intnRear; //尾charszQueue[MAX_SIZE][MAX_LEN];};//定义一个栈的结构structSTACK{intnMaxSize; //最大值intnTop; //栈顶charszStack[MAX_SIZE][MAX_LEN];};//队列的操作voidInitQueue(QUEUE*q,intnMaxSize){q->nMaxSize=nMaxSize;q->nCount=0;q->nFront=0;q->nRear=0;q->szQueue[MAX_SIZE][MAX_LEN]=0;}voidInQueue(QUEUE*q,char*pItem){if(q->nCount==q->nMaxSize){printf("Queueisfull!\n");return;}strcpy(q->szQueue[q->nRear],pItem);if(q->nRear
内容来自淘豆网www.taodocs.com转载请标明出处.