欧美色欧美亚洲高清在线观看,国产特黄特色a级在线视频,国产一区视频一区欧美,亚洲成a 人在线观看中文

  1. <ul id="fwlom"></ul>

    <object id="fwlom"></object>

    <span id="fwlom"></span><dfn id="fwlom"></dfn>

      <object id="fwlom"></object>

      實(shí)驗(yàn)三 棧和隊(duì)列

      時(shí)間:2019-05-12 14:10:14下載本文作者:會(huì)員上傳
      簡介:寫寫幫文庫小編為你整理了多篇相關(guān)的《實(shí)驗(yàn)三 棧和隊(duì)列》,但愿對你工作學(xué)習(xí)有幫助,當(dāng)然你在寫寫幫文庫還可以找到更多《實(shí)驗(yàn)三 棧和隊(duì)列》。

      第一篇:實(shí)驗(yàn)三 棧和隊(duì)列

      實(shí)驗(yàn)報(bào)告三 棧和隊(duì)列

      班級: 姓名: 學(xué)號: 專業(yè):

      一、實(shí)驗(yàn)?zāi)康模?/p>

      (1)掌握棧的基本操作的實(shí)現(xiàn)方法。

      (2)利用棧先進(jìn)后出的特點(diǎn),解決一些實(shí)際問題。(3)掌握鏈?zhǔn)疥?duì)列及循環(huán)隊(duì)列的基本操作算法。(4)應(yīng)用隊(duì)列先進(jìn)先出的特點(diǎn),解決一些實(shí)際問題。

      二、實(shí)驗(yàn)內(nèi)容:

      1、使用一個(gè)棧,將一個(gè)十進(jìn)制轉(zhuǎn)換成二進(jìn)制。粘貼源程序:

      package Word1;

      public class Node {

      } T data;Node next;public Node(T a){ } public Node(T a,Node n){

      } this.data=a;this.next=n;this(a,null);

      -----package Word1;

      public class Stack {

      } public Node Top;public Stack(){ } public void push(T a){ } public T Out(){

      }

      T a=this.Top.data;this.Top=this.Top.next;return a;this.Top=new Node(a,this.Top);this.Top=null;

      --package Word1;

      import java.util.*;

      public class Test {

      } static Scanner scan=new Scanner(System.in);static int temp=0;static int a=0;static Stack s=new Stack();public static void main(String[] args){

      } temp=scan.nextInt();while(true){

      } while(s.Top!=null){

      } System.out.printf(“%d”,s.Out());a=temp%2;s.push(a);temp=temp/2;if(temp==0)break;

      粘貼測試數(shù)據(jù)及運(yùn)行結(jié)果:

      2、回文是指正讀反讀均相同的字符序列,如“acdca”、“dceecd”均是回文,但“book”不是回文。利用1中的基本算法,試寫一個(gè)算法判定給定的字符串是否為回文。(提示:將一半字符入棧,依次彈出與另一半逐個(gè)比較)粘貼源程序:---------package Word1;

      import java.util.*;public class Test1 {

      } static Scanner sc=new Scanner(System.in);static char[] c={'a','b','c','b','a'};static Stack s=new Stack();public static void main(String[] args){

      } public static String One(){

      } public static String Two(){

      } for(int i=0;i<(c.length/2);i++){ } for(int i=c.length/2;i

      } return “該字符串是回文”;if(s.Out()!=c[i])return “該字符不是回文”;s.push(c[i]);for(int i=0;i<(c.length/2);i++){ } for(int i=c.length/2+1;i

      } return “該字符串是回文”;if(s.Out()!=c[i])return “該字符串不是回文”;s.push(c[i]);if(c.length%2!=0){

      } else{ } System.out.println(Two());System.out.println(One());

      -------------

      粘貼測試數(shù)據(jù)及運(yùn)行結(jié)果:

      3、使用3個(gè)隊(duì)列分別保留手機(jī)上最近10個(gè)“未接來電”、“已接來電”、“已撥電話”。

      粘貼源程序:

      package Word3;

      import java.util.*;

      public class Queue {

      LinkedList list;public Queue(){ } public void enQ(E a){ } public E deQ(){ } public boolean isEmpty(){ } public void Pri(){ while((list.isEmpty()))return list.isEmpty();return list.removeLast();list.addLast(a);list=new LinkedList();

      } } System.out.printf(“%d n”,this.deQ());

      package Word3;

      import java.util.*;

      public class Test {

      static Queue list1=new Queue();static Queue list2=new Queue();static Queue list3=new Queue();static Scanner sc=new Scanner(System.in);public static void main(String[] args){ } public static void Frame(){

      } static private void T2(){

      int c;int[] a={22324,321321,222333};for(int i=0;i

      1、查詢

      2、增加”);c=sc.nextInt();if(c==1){

      } else{ c=sc.nextInt();while(!(list2.isEmpty()))System.out.printf(“%d n”,list2.deQ());list2.enQ(a[i]);int c=0;System.out.println(“請選擇記錄類型:”);System.out.println(“

      1、未接來電

      2、已接來電

      3、已撥電話”);switch(c=sc.nextInt()){

      } case 1:T1();break;case 2:T2();break;case 3:T3();break;Frame();

      }

      } list2.enQ(c);while(!(list2.isEmpty()))System.out.printf(“%d n”,list2.deQ());sc.close();static private void T3(){

      } static private void T1(){

      int c;int[] a={12324,321321,222333};for(int i=0;i

      1、查詢

      2、增加”);c=sc.nextInt();if(c==1){

      } else{ c=sc.nextInt();while(!(list1.isEmpty()))System.out.printf(“%d n”,list1.deQ());list1.enQ(a[i]);int c;int[] a={32324,321321,222333};for(int i=0;i

      1、查詢

      2、增加”);c=sc.nextInt();if(c==1){

      } else{

      } sc.close();c=sc.nextInt();list3.enQ(c);while(!(list3.isEmpty()))System.out.printf(“%d n”,list3.deQ());while(!(list3.isEmpty()))System.out.printf(“%d n”,list3.deQ());list3.enQ(a[i]);

      }

      }

      } list1.enQ(c);while(!(list1.isEmpty()))System.out.printf(“%d n”,list1.deQ());sc.close();

      粘貼測試數(shù)據(jù)及運(yùn)行結(jié)果:

      三、心得體會(huì):(含上機(jī)中所遇問題的解決辦法,所使用到的編程技巧、創(chuàng)新點(diǎn)及編程的心得)

      第二篇:實(shí)驗(yàn)三 棧和隊(duì)列的應(yīng)用

      一、實(shí)驗(yàn)?zāi)康?掌握棧的數(shù)據(jù)類型描述及棧的特點(diǎn); 掌握棧的順序存儲結(jié)構(gòu)的特點(diǎn)及算法描述; 掌握隊(duì)列的數(shù)據(jù)類型描述及鏈?zhǔn)酱鎯Y(jié)構(gòu)的特點(diǎn)和算法描述。

      二、實(shí)驗(yàn)內(nèi)容

      停車場管理。設(shè)有一個(gè)可以停放n輛汽車的狹長停車場(先進(jìn)后出),它只有一個(gè)大門可以供車輛進(jìn)出。車輛按到達(dá)停車場時(shí)間的先后依次從停車場最里面向大95E8口處停放(最先到達(dá)的第一輛車停放在停車場的最里面)。如果停車場已放滿n輛車,則后來的車輛只能在停車場大門外的便道上等待,一旦停車場內(nèi)有車離開,則排在便道上的第一輛車就可以進(jìn)入停車場。停車場內(nèi)如有某輛車要離開,在它之后進(jìn)入停車場的車都必須先退出停車場為它讓路,待其開出停車場后,這些車再按原來的次序進(jìn)停車場。每輛車在離開停車場時(shí),都應(yīng)根據(jù)它在停車場內(nèi)停留的時(shí)間長短交費(fèi)。如果停留在便道上的車沒進(jìn)停車場就要離開,允許其離開,不收停車費(fèi),并且仍然保持在便道上的車輛次序。試編程模擬停車場管理。

      三、算法描述

      提示:可以將停車場定義成一個(gè)順序棧s1,便道定義成一個(gè)鏈隊(duì)列q,而停車場中的某輛車要離開,則在它后面進(jìn)停車場的車必須讓道,讓其離開,故還必須有一個(gè)臨時(shí)的順序棧s2,存放讓道的車輛。

      當(dāng)有車輛進(jìn)停車場時(shí),直接進(jìn)入s1棧,若s1棧滿,則進(jìn)入便道(鏈隊(duì)列q)。若有s1中車輛x離開時(shí),先讓在x后面進(jìn)棧的車從s1退棧并進(jìn)棧到s2中,讓x離開并收取停車費(fèi),然后,再把s2中的所有車輛退棧并重新進(jìn)入s1棧,最后,將鏈隊(duì)列q的隊(duì)頭車輛進(jìn)棧到s1中并刪除隊(duì)頭車輛。若有鏈隊(duì)列q(便道)中的車輛y離開時(shí),從鏈隊(duì)列中刪除該車輛即可,不收停車費(fèi)。

      車輛的數(shù)據(jù)可以表示為(車輛編號,到達(dá)/離開時(shí)間)。

      四.程序清單: #include using namespace std;const int StackSize=5;class SeqStack { public:

      SeqStack(){top=-1;} ~SeqStack(){};void Push(int x);void Push2(int x);int *Return();int Pop(int y);int Count();void PrintStack();private: int data[StackSize];int top;};//入棧

      void SeqStack::Push(int x){ if(top>=StackSize-1)throw“上溢”;for(int i=0;i<=top+1;i++){

      if(data[i]==x)

      {

      cout<<“該車牌已經(jīng)存在!請重新輸入: ”;

      i=-1;

      cin>>x;

      } } top++;data[top]=x;} //返回?cái)?shù)組地址

      int *SeqStack::Return(){ return data;} //臨時(shí)棧

      void SeqStack::Push2(int x){ top++;data[top]=x;

      } //輸出函數(shù)

      void SeqStack::PrintStack(){ for(int i=0;i<=top;i++)

      cout<<“位置為”<

      int SeqStack::Pop(int y){ if(top==-1)throw“下溢”;int x;x=data[top--];if(y==top+2)data[top+1]=123456789;if(top==-1)data[top+1]=123456789;return x;} //數(shù)數(shù)

      int SeqStack::Count(){ return top;}

      //隊(duì)列

      struct Node { int data;Node *next;};class LinkQueue { public: LinkQueue();void EnQueue(int x,int *q);void xzDeQueue(int x);int Count();int DeQueue();

      private: Node *front,*rear;};//構(gòu)造函數(shù)

      LinkQueue::LinkQueue(){ Node *s=new Node;s->next=NULL;front=rear=s;} //入隊(duì)

      void LinkQueue::EnQueue(int x,int *q){ Node *s=new Node;Node *p=new Node;p=front;while(p){

      if(p->data ==x)

      {

      cout<<“便道已有該車牌號,請重新輸入: ”;

      cin>>x;

      for(int i=0;i<5;i++)

      {

      if(x==q[i])

      {

      cout<<“停車場已有該車牌號,請重新輸入: ”;

      cin>>x;

      i=-1;

      }

      }

      p=front;} p=p->next;} s->data =x;s->next =NULL;

      rear->next =s;rear=s;} //出隊(duì)

      int LinkQueue::DeQueue(){ if(front==rear)throw“便道無車輛”;Node *p=new Node;int x;p=front->next;x=p->data;front->next =p->next;if(p->next ==NULL)rear=front;delete p;return x;} //計(jì)算結(jié)點(diǎn)數(shù)

      int LinkQueue::Count(){ Node *p=new Node;p=front;int i=0;while(p&&p->next!=NULL){

      p=p->next;

      i++;} return i;} //選擇性出隊(duì)

      void LinkQueue::xzDeQueue(int x){ if(rear==front)throw“便道無車輛”;Node *p=new Node;p=front;int y;int i=0;for(;p->next!=NULL;p=p->next)

      {

      if(p->next->data ==x)

      if(p->next->next!=NULL)

      {

      Node *q=new Node;

      q=p->next;

      y=q->data;

      p->next =q->next;

      i=1;

      delete q;

      cout<<“車牌號為:”<

      break;

      }

      else

      {

      Node *q=new Node;

      q=p->next;

      y=q->data;

      p->next =NULL;

      i=1;

      delete q;

      if(front->next==NULL)rear=front;

      cout<<“車牌號為:”<

      break;

      }

      } if(i==0)cout<<“無車牌號為:”<

      SeqStack b;//b是作為臨時(shí)存放車輛的棧

      LinkQueue c;//c是作為便道的隊(duì)列

      cout<<“tttt1.車輛進(jìn)入”<

      cout<<“tttt4.便道車輛離開”<

      int xh1=1;//xh1為菜單最外層的循環(huán)控制變量

      int time[100];//記錄各車輛進(jìn)入停車場的時(shí)間

      int t1=0;//作為車輛對應(yīng)的時(shí)間編號

      int money=1;while(xh1==1){

      cout<<“請選擇指令: ”;

      cin>>zl;

      switch(zl)

      {

      case 1:

      try{

      int n1=a.Count();

      int n;

      cout<<“請輸入車牌號: ”;

      cin>>n;

      if(n1==4)

      {

      int *Num=a.Return();

      for(int i=0;i<=4;i++)

      if(Num[i]==n)

      {

      cout<<“停車場已有該車牌號,請重新輸入!”;

      cin>>n;

      i=-1;

      }

      int *CarNum=a.Return();

      c.EnQueue(n,CarNum);

      cout<<“停車場已滿,請?jiān)诒愕赖群?”<

      break;

      }

      a.Push(n);

      cout<<“請輸入進(jìn)入時(shí)間: ”;

      cin>>time[t1];

      while(time[t1]<0||time[t1]>=24)

      {

      cout<<“請輸入正確的時(shí)間(0~23時(shí)):”;

      cin>>time[t1];

      }

      t1++;

      }

      catch(char*s){cout<

      break;

      case 2:

      try{int n2;//離開車輛的編號

      cout<<“請輸入要離開的車的位置: ”;

      cin>>n2;

      if(a.Count()+1==0)

      {

      cout<<“該停車場沒有車輛,請選擇其他操作!”;

      break;

      }

      else

      while(n2<1||n2>a.Count()+1)

      {

      cout<<“請輸入1~”<

      cin>>n2;

      }

      int j=a.Count();

      for(int i=0;i<(j+1-n2);i++)

      b.Push2(a.Pop(n2));

      a.Pop(n2);

      int j2=b.Count();

      for(int i1=0;i1<=j2;i1++)

      a.Push(b.Pop(n2));

      int j3=c.Count();

      int time1;

      cout<<“請輸入離開時(shí)間: ”;

      cin>>time1;

      while(time1<0||time1>23)

      {

      cout<<“請輸入正確的時(shí)間(0~23時(shí)): ”;

      cin>>time1;

      }

      int day=0;

      if(time1

      {

      cout<<“離開時(shí)間已小于進(jìn)入時(shí)間!請加上停留天數(shù)(天):”;

      cin>>day;

      while(day<=0)

      {

      cout<<“輸入的天數(shù)必須大于0:”;

      cin>>day;

      }

      }

      cout<<“您的費(fèi)用是(元): ”<<(time1-time[n2-1]+24*day)*money<

      for(int i2=0;i2<(j+1-n2);i2++)

      time[n2-1+i2]=time[n2+i2];

      t1--;

      if(j3!=0)

      {

      a.Push(c.DeQueue());

      cout<<“ttt通知: 便道車輛請進(jìn)入停車場!”<

      cout<<“請輸入進(jìn)入時(shí)間: ”;

      cin>>time[t1];

      while(time[t1]<0||time[t1]>=24)

      {

      cout<<“請輸入正確的時(shí)間(0~23時(shí)):”;

      cin>>time[t1];

      }

      t1++;

      }

      }catch(char *s){cout<

      break;

      case 3:

      a.PrintStack();break;

      case 4:

      int n3;

      cout<<“請輸入離開車輛的車牌號: ”;

      cin>>n3;try{

      c.xzDeQueue(n3);}catch(char*s){cout<

      break;

      case 5:

      cout<<“請輸入單價(jià): ”;

      cin>>money;

      cout<<“修改成功!”<

      cout<<“當(dāng)前停車場的費(fèi)用是:”<

      break;

      case 6:

      xh1=0;

      break;

      } } system(“pause”);}

      心得體會(huì):

      完成時(shí)間:2010-10-30

      第三篇:實(shí)驗(yàn)總結(jié)報(bào)告-棧和隊(duì)列

      實(shí)驗(yàn)總結(jié)報(bào)告—棧和隊(duì)列

      學(xué)號:

      姓名: 時(shí)間:

      一、目的 1.做實(shí)驗(yàn)的目的

      加深對線性結(jié)構(gòu)棧和隊(duì)列的理解,學(xué)會(huì)定義棧和隊(duì)列的存儲結(jié)構(gòu),加強(qiáng)對棧和隊(duì)列操作機(jī)制的理解,掌握棧和隊(duì)列的基本操作,了解棧和隊(duì)列的一些應(yīng)用。2.撰寫實(shí)驗(yàn)報(bào)告的目的

      對本次實(shí)驗(yàn)情況進(jìn)行總結(jié),加強(qiáng)對實(shí)驗(yàn)內(nèi)容的理解,對實(shí)驗(yàn)過程有一個(gè)系統(tǒng)的認(rèn)識,從中獲得本次試驗(yàn)的經(jīng)驗(yàn),并對實(shí)驗(yàn)結(jié)果進(jìn)行適當(dāng)?shù)姆治?,加深對棧和?duì)列的理解和認(rèn)識。

      二、內(nèi)容

      1.說明實(shí)驗(yàn)次數(shù)及實(shí)驗(yàn)內(nèi)容 本次實(shí)驗(yàn)用一次實(shí)驗(yàn)課時(shí)完成 實(shí)驗(yàn)內(nèi)容:

      (1)、編寫函數(shù)CreatStack_sq(), DestoryStack_sq(), Push_sq(), Pop_sq(),StackEmpty_sq()和

      StackTraverse_sq(),分別完成創(chuàng)建空棧,銷毀棧,入棧,出棧,判斷棧是否為空,遍歷棧底到棧頂依

      次打印棧內(nèi)元素等功能(不要修改原棧),完成后進(jìn)行測試。測試要求:在main 中,建立棧;判斷棧是否為空;將0~9 入棧;將棧頂兩個(gè)元素出棧, 兩元素求和后再入棧;從棧底到棧頂依次打印元素,再從棧頂?shù)綏5状蛴≡?;銷毀棧。

      void CreatStack_sq(SqStack &S, int msize = STACK_INIT_SIZE){...} void DestoryStack_sq(SqStack &S){...}void Push_sq(SqStack &S, ElementType e){...} bool Pop_sq(SqStack &S, ElementType &e){...} bool StackEmpty_sq(SqStack S){...} bool StackTraverse_sq(SqStack S){...}(2)、編寫函數(shù), CreateQueue_L(), DestoryQueue_L(), EnQueue_L(),DeQueue_L(),分別完

      成創(chuàng)建隊(duì)列,銷毀隊(duì)列,入隊(duì)列,出隊(duì)列等操作,完成后進(jìn)行測試。測試要求:在主程序中,建立隊(duì)列,將0~9 依次入隊(duì)列,按入隊(duì)列順序出隊(duì)列并打印, 銷毀隊(duì)列。

      void CreateQueue_L(LinkQueue &Q){ } void DestoryQueue_L(LinkQueue &Q){ } void EnQueue_L(LinkQueue &Q,int e){ } bool DeQueue_L(LinkQueue &Q, int &e){ }(3)、回文是指正讀反讀均相同的字符序列,如”abba”和”abdba”均是回文, 但”good”不是回文。根據(jù)第四章棧和隊(duì)列所學(xué)內(nèi)容,試寫一個(gè)算法判

      定給定的字符向量是否為回文。測試數(shù)據(jù): 2.1 char* ch = “abccba”;2.2 char* ch = “abccbd”;(4)、(附加題)編寫函數(shù)void Knapsack(int w[],int T,int n),完成背包求解問題。測試數(shù)據(jù): w[6] = {2,8,6,5,1,4};2.做實(shí)驗(yàn)完成情況

      實(shí)驗(yàn)內(nèi)容在實(shí)驗(yàn)課時(shí)時(shí)間內(nèi)完成(提前編寫了大概1/3部分的代碼),選做內(nèi)容也完成。

      本次實(shí)驗(yàn)內(nèi)容較多,為使代碼看著簡潔有條理,采用了建工程的方式。棧部分:

      自定義了頭文件 L_stack.h: /*自定義頭文件*/ #include

      #define STACK_INIT_SIZE 100;#define STACKINCREMENT 100;

      /*自定義頭文件(棧相關(guān))*/

      #include typedef char ElemType;//typedef int ElemType;

      /*棧的結(jié)構(gòu)體定義*/ typedef struct{

      ElemType *elem;int top;int stacksize;}SqStack;

      void CreateStack_sq(SqStack &S,int msize);//創(chuàng)建棧,msize為棧的大小 void DestroyStack_sq(SqStack &S);//銷毀棧

      void Push(SqStack &S, ElemType e);// 進(jìn)棧操作,e為入棧元素 int Pop_sq(SqStack &S, ElemType &e);//出站操作,成功返回0,不成功返回-1 void Increment(SqStack &S, int inc_size);//增加??臻g int StackEmpty_sq(SqStack S);//判斷??眨瑮?辗祷?,棧非空返回-1; void StackTraverse_sq1(SqStack S);//遍歷棧底到棧頂,若棧非空則依次打印棧中元素

      void StackTraverse_sq2(SqStack S);//遍歷棧頂?shù)綏5?,若棧非空則依次打印棧中元素

      void Test_sq();//棧的檢測程序

      void MatchBracket_sq(char exp[]);// 括號匹配 void MatchWord_sq(char exp[]);//判斷回文 void knapsack(int w[], int T, int n);//背包問題

      在頭文件中對所有要用到的自定義函數(shù)進(jìn)行了聲明,各函數(shù)的功能可見代碼注釋部分。

      棧的創(chuàng)建:

      #include“L_stack.h”

      void CreateStack_sq(SqStack &S,int msize){

      S.elem = new ElemType[msize];S.stacksize = msize;S.top =-1;}//end CreateStack_sq 此操作完成棧的創(chuàng)建,創(chuàng)建完成得到一個(gè)空棧。

      棧的銷毀:

      #include“L_stack.h”

      void DestroyStack_sq(SqStack &S){

      delete S.elem;S.top =-1;S.stacksize = 0;}//end DestroyStack_sq 此操作將棧銷毀。

      入棧:

      #include“L_stack.h” #include

      void Push(SqStack &S, ElemType e){

      if(S.top == S.stacksize0;break;case '}':

      if(!Pop_sq(S, e)|| e!= '{')matchstat = 0;break;}//end switch ch = *exp++;}//end while

      if(matchstat&&StackEmpty_sq(S))printf(“括號匹配n”);else printf(“括號不匹配n”);}//end MatchBracket_sq 該操作完成括號的匹配;

      回文判斷:

      #include“L_stack.h”

      void MatchWord_sq(char exp[]){

      int i, len=0,flag=1;SqStack S;CreateStack_sq(S, 100);char ch,e;for(i = 0;exp[i]!='