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

📄 stack.cpp

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

 /**************************************************************************
  **************************************************************************
  *******************************  STACK.CPP  ******************************
  **************************************************************************
  **************************************************************************/

  /*************************************************************************

	  By :
		Muhammad Tahir Shahzad  [ MTS ]
		B.C.S Honours  [ 2000-04 ]
		Government College University Lahore
		Pakistan

      E-mail :  mtshome@wol.net.pk

    Web-Site :  www.mts-home.cjb.net  [ www.wol.net.pk/mtshome ]
		www.mtshome.cjb.net   [ www.geocities.com/mtahirshahzad ]

  *************************************************************************/

 /**************************************************************************/
 /**************************************************************************/
 //---------------------------  HEADER FILES  -----------------------------//
 /**************************************************************************/
 /**************************************************************************/

 /**************************************************************************/
 //---------------------------  User Defined  -----------------------------//
 /**************************************************************************/

 # include "Linklist.H"

 /**************************************************************************/
 /**************************************************************************/
 //---------------------  FUNCTION DEFINITIONS  ---------------------------//
 /**************************************************************************/
 /**************************************************************************/

 /**************************************************************************/
 //----------------------  Linked_list_Stack( )  --------------------------//
 /**************************************************************************/

 Linked_List_Stack::Linked_List_Stack ( )
    {
       top=NULL;
       bottom=NULL;
       pushed_element_count=0;
    }

 /**************************************************************************/
 //----------------------  show_main_screen( )  ---------------------------//
 /**************************************************************************/

 void Linked_List_Stack::show_stack_screen( )
    {
       cleardevice( );

       setcolor(15);
       setlinestyle(1,0,3);
	 rectangle(5,5,getmaxx( )-5,getmaxy( )-5);

       setlinestyle(0,0,0);

       show_window(5,5,getmaxx( )-5,80);

       setfillpattern(fill_pattern,4);
	 bar(13,13,getmaxx( )-13,72);

       settextstyle(3,0,4);
	 setcolor(0);
	   outtextxy(17,22,"Implementation of Linked List as Stack");
	   outtextxy(18,22,"Implementation of Linked List as Stack");

	 setcolor(14);
	   outtextxy(19,20,"Implementation of Linked List as Stack");
	   outtextxy(20,20,"Implementation of Linked List as Stack");
	   outtextxy(21,20,"Implementation of Linked List as Stack");

       show_window(5,82,305,getmaxy( )-5);

       setfillpattern(fill_pattern,9);
	 bar(14,91,296,getmaxy( )-14);

       setcolor(6);
       setfillstyle(1,6);
	 pieslice(215,105,0,360,10);

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

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

       setcolor(7);
	 circle(215,105,11);
	 circle(245,105,11);
	 circle(275,105,11);

       show_window(307,82,getmaxx( )-5,getmaxy( )-5);

       settextstyle(7,0,4);
	 setcolor(0);
	   outtextxy(16,111,"Press:");

	 setcolor(10);
	   outtextxy(17,110,"Press:");
	   outtextxy(18,110,"Press:");

       settextstyle(2,0,6);
	 setcolor(0);
	   outtextxy(59,151,"<P> to Push an Element");
	   outtextxy(59,171,"<O> to Pop an Element");
	   outtextxy(59,191,"<E> to Exit");

	 setcolor(14);
	   outtextxy(60,150,"<P> to Push an Element");
	   outtextxy(61,150,"<P> to Push an Element");

	   outtextxy(60,170,"<O> to Pop an Element");
	   outtextxy(61,170,"<O> to Pop an Element");

	   outtextxy(60,190,"<E> to Exit");
	   outtextxy(61,190,"<E> to Exit");

       setfillstyle(2,1);
	 bar(317,92,getmaxx( )-15,getmaxy( )-15);
    }

 /**************************************************************************/
 //------------------------  show_output_screen( )  -----------------------//
 /**************************************************************************/

 void Linked_List_Stack::show_stack_output_screen( )
    {
       for(int count=0;count<=187;count++)
	  {
	     setfillstyle(1,0);
	       bar(317,280,getmaxx( )-15,278-count);
	       bar(317,280,getmaxx( )-15,278+count);

	     delay(5);
	  }

       setcolor(12);
       settextstyle(2,0,7);
	 outtextxy(405,400,"Linked List (Stack)");
	 outtextxy(406,400,"Linked List (Stack)");
	 outtextxy(407,400,"Linked List (Stack)");

       setfillstyle(1,6);
	 bar(402,420,618,422);

       setcolor(15);
       setlinestyle(0,0,3);
	 rectangle(330,405,390,435);

       setfillstyle(1,9);
	 bar(331,406,374,434);

       setfillstyle(1,1);
	 bar(376,406,389,434);

	 line(375,405,375,435);

       setcolor(7);
       setlinestyle(0,0,0);
	 line(352,425,352,455);
	 line(352,455,415,455);

	 line(412,452,415,455);
	 line(412,458,415,455);

	 line(382,423,382,443);
	 line(382,443,415,443);

	 line(412,440,415,443);
	 line(412,446,415,443);

       setfillstyle(1,15);
	 pieslice(382,420,0,360,2);

       settextstyle(0,0,1);
	 setcolor(15);
	   outtextxy(320,402,"*");

	 setcolor(9);
	   outtextxy(420,452,"Entry->Data");
	   outtextxy(420,438,"Entry->Next (x=NULL)");

	 setcolor(11);
	   outtextxy(333,417,"00000");
    }

 /**************************************************************************/
 //-------------------------------  push( )  ------------------------------//
 /**************************************************************************/

 void Linked_List_Stack::push( )
    {
       long num=get_element(SINGLE);

       for(int count=1;count<5;count++)
	  {
	     setcolor(0);
	     setfillstyle(1,0);
	       pieslice(215,105,0,360,10);

	     delay(250);

	     setcolor(6);
	     setfillstyle(1,6);
	       pieslice(215,105,0,360,10);

	     delay(300);
	  }

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

	     sound(1500);
	     delay(800);
	     nosound( );

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

       if(pushed_element_count==15)
	  {
	     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);
	  }

       entry=new(node);

       if(pushed_element_count==15)
	  {
	     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(2,0,8);
		     setcolor(0);
		       outtextxy(46,309,"Not enough heap");
		       outtextxy(47,309,"Not enough heap");

		       outtextxy(28,335,"space on Screen.");
		       outtextxy(29,335,"space on Screen.");

		     setcolor(12);
		       outtextxy(48,308,"Not enough heap");
		       outtextxy(49,308,"Not enough heap");
		       outtextxy(50,308,"Not enough heap");

		       outtextxy(30,334,"space on Screen.");
		       outtextxy(31,334,"space on Screen.");
		       outtextxy(32,334,"space on Screen.");

		   delay(500);

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

		   delay(400);
		}

	     getch( );
	     clear_element_screen(1);
	  }

       else if(bottom==NULL)
	  {
	     entry->data=num;
	     entry->next=NULL;
	     bottom=entry;
	     top=entry;

	     pushed_element_count++;
	  }

       else
	  {
	     entry->data=num;
	     entry->next=NULL;
	     top->next=entry;
	     top=entry;

	     pushed_element_count++;
	  }

       print_stack( );
    }

 /**************************************************************************/
 //----------------------------  pop( )  ----------------------------------//
 /**************************************************************************/

 void Linked_List_Stack::pop( )
    {
       for(int count=1;count<5;count++)
	  {
	     setcolor(0);
	     setfillstyle(1,0);
	       pieslice(215,105,0,360,10);

	     delay(250);

	     setcolor(6);
	     setfillstyle(1,6);
	       pieslice(215,105,0,360,10);

⌨️ 快捷键说明

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