⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stack.cpp

📁 graphical implementation of linked list
💻 CPP
📖 第 1 页 / 共 2 页
字号:

	     delay(300);
	  }

       if(pushed_element_count==0)
	  {
	     setcolor(12);
	     setfillstyle(1,12);
	       pieslice(275,105,0,360,10);

	     sound(2500);
	     delay(1000);
	     nosound( );

	     setcolor(4);
	     setfillstyle(1,4);
	       pieslice(275,105,0,360,10);

	     delay(200);
	  }

       else if(pushed_element_count>0)
	  {
	     setcolor(10);
	     setfillstyle(1,10);
	       pieslice(245,105,0,360,10);

	     sound(3000);
	     delay(800);
	     nosound( );

	     setcolor(2);
	     setfillstyle(1,2);
	       pieslice(245,105,0,360,10);
	  }

       if(bottom==NULL)
	  {
	     show_push_pop_screen(WARNING);

	     settextstyle(7,0,4);
	       setcolor(0);
		 outtextxy(25,277,"Error:");
		 outtextxy(26,277,"Error:");

	       setcolor(14);
		 outtextxy(27,275,"Error:");
		 outtextxy(28,275,"Error:");

	     while(!kbhit( ))
		{
		   settextstyle(6,0,4);
		     setcolor(0);
		       outtextxy(48,306,"Nothing to Pop");
		       outtextxy(49,306,"Nothing to Pop");

		     setcolor(12);
		       outtextxy(50,305,"Nothing to Pop");
		       outtextxy(51,305,"Nothing to Pop");
		       outtextxy(52,305,"Nothing to Pop");

		   delay(500);

		   setfillstyle(1,9);
		     bar(23,315,277,350);

		   delay(400);
		}

	     getch( );
	  }

       else
	  {
	     for(last_entry=bottom;last_entry->next!=NULL;
						 last_entry=last_entry->next)
		second_last_entry=last_entry;

	     if(top==bottom)
		bottom=NULL;

	     long poped_element=top->data;

	     delete(top);

	     top=second_last_entry;
	     top->next=NULL;
	     pushed_element_count--;

	     char element[6]={'\0'};

	     ltoa(poped_element,element,10);

	     show_stack_element_screen(POP);

	     setcolor(12);
	     settextstyle(2,0,7);
	       outtextxy(140,305,element);
	       outtextxy(141,305,element);

	     delay(2500);
	  }

       clear_element_screen(POP);
       print_stack( );
    }

 /**************************************************************************/
 //------------------------  print_linked_list( )  ------------------------//
 /**************************************************************************/

 void Linked_List_Stack::print_stack( )
    {
       int count=0;
       int x=340;
       int y=100;

       print=bottom;

       setfillstyle(1,0);
	 bar(317,92,getmaxx( )-15,getmaxy( )-80);

       while(print!=NULL)
	  {
	     setcolor(15);
	     setlinestyle(0,0,3);
	       rectangle(x,y,x+60,y+30);

	     char element[6]={NULL};

	     ltoa(print->data,element,10);

	     if(count==0 || count==1 || count==2 || count==6 || count==7 ||
			     count==8 || count==12 || count==13 || count==14)
		{
		   setfillstyle(1,9);
		     bar(x+1,y+1,x+44,y+29);

		   setfillstyle(1,1);
		     bar(x+46,y+1,x+59,y+29);

		   setcolor(15);
		     line(x+45,y,x+45,y+30);

		   setcolor(11);
		   settextstyle(0,0,1);
		     outtextxy(x+3,y+10,element);

		   if(count==pushed_element_count-1)
		      {
			 setcolor(15);
			 outtextxy(x+50,y+11,"x");
		      }
		}

	     else
		{
		   setfillstyle(1,9);
		     bar(x+16,y+1,x+59,y+29);

		   setfillstyle(1,1);
		     bar(x+1,y+1,x+14,y+29);

		   setcolor(15);
		     line(x+15,y,x+15,y+30);

		   if(count==pushed_element_count-1)
		      delay(500);

		   setcolor(11);
		   settextstyle(0,0,1);
		     outtextxy(x+18,y+10,element);

		   if(count==pushed_element_count-1)
		      {
			 setcolor(15);
			 outtextxy(x+4,y+11,"x");
		      }
		}

	     if(count==1 || count==2 || count==7 || count==8 || count==13
								|| count==14)
		{
		   setcolor(15);
		     line(x-45,y+15,x,y+15);

		   setfillstyle(1,15);
		     pieslice(x-47,y+15,0,360,2);

		     line(x-6,y+11,x-2,y+15);
		     line(x-6,y+19,x-2,y+15);
		}

	     else if(count==4 || count==5 || count==10 || count==11)
		{
		   setcolor(15);
		     line(x+60,y+15,x+105,y+15);

		   setfillstyle(1,15);
		     pieslice(x+107,y+15,0,360,2);

		     line(x+66,y+11,x+62,y+15);
		     line(x+66,y+19,x+62,y+15);
		}

	     else if(count==3 || count==9)
		{
		   setcolor(15);
		     setfillstyle(1,15);
		       pieslice(x+53,y-45,0,360,2);

		     setlinestyle(0,0,3);
		       line(x+55,y-45,x+75,y-45);
		       line(x+75,y-45,x+75,y+15);
		       line(x+60,y+15,x+75,y+15);

		       line(x+62,y+15,x+66,y+11);
		       line(x+62,y+15,x+66,y+19);
		}

	     else if(count==6 || count==12)
		{
		   setcolor(15);
		     setfillstyle(1,15);
		       pieslice(x+7,y-45,0,360,2);

		     setlinestyle(0,0,3);
		       line(x-15,y-45,x+10,y-45);
		       line(x-15,y-45,x-15,y+15);
		       line(x-15,y+15,x,y+15);

		       line(x-2,y+15,x-6,y+11);
		       line(x-2,y+15,x-6,y+19);
		}

	     setcolor(7);
	     setlinestyle(0,0,3);
	       line(350,125,350,138);
	       line(346,134,350,138);
	       line(354,134,350,138);

	     setcolor(14);
	     settextstyle(2,0,4);
	       outtextxy(330,140,"Bottom");

	     if(count==pushed_element_count-1)
		{
		   setcolor(7);
		   setlinestyle(0,0,3);
		    line(x+30,y+25,x+30,y+38);
		    line(x+26,y+34,x+30,y+38);
		    line(x+34,y+34,x+30,y+38);

		   setcolor(14);
		   settextstyle(2,0,4);
		     outtextxy(x+30,y+40,"Top");
		}

	     print=print->next;
	     count++;

	     if(count==0 || count==1 || count==2 || count==6 || count==7 ||
			     count==8 || count==12 || count==13 || count==14)
		x+=100;

	     else if(count==3 || count==4 || count==5 || count==9 ||
		     count==10 ||  count==11)
		x-=100;

	     if(count==3 || count==9)
		{
		   x=540;
		   y+=60;
		}

	     else if(count==6 || count==12)
		{
		   x=340;
		   y+=60;
		}

	      if(count==15)
		 break;
	  }

       setlinestyle(0,0,0);
    }

 /**************************************************************************/
 //---------------------------  show_working( )  --------------------------//
 /**************************************************************************/

 void Linked_List_Stack::show_stack_working( )
    {
       show_stack_screen( );
       delay(1000);
       show_stack_output_screen( );

       char Key;
       int selected=0;

       do
	  {
	     waiting_for_input( );
	     Key=getch( );

	     switch(Key)
		{
		   case 'p': push( );
			     break;

		   case 'P': push( );
			     break;

		   case 'o': pop( );
			     break;

		   case 'O': pop( );
			     break;

		   case 'e': selected=1;
			     break;

		   case 'E': selected=1;
			     break;
		}
	  }
       while(int(Key)!=27 && !selected);

       delay(1000);
    }

 /**************************************************************************/
 /**************************************************************************/
 //------------------------ THE  END  -------------------------------------//
 /**************************************************************************/
 /**************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -