| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 648 人关注过本帖
标题:c改成java 双向链表的图形分步演示 哪位大哥帮帮忙 谢谢了!
只看楼主 加入收藏
jc184892058
Rank: 2
等 级:论坛游民
帖 子:7
专家分:20
注 册:2010-12-2
结帖率:100%
收藏
 问题点数:0 回复次数:4 
c改成java 双向链表的图形分步演示 哪位大哥帮帮忙 谢谢了!
#include <graphics.h>
#include <stdio.h>
#include <string.h>
#define x0 30
#define y0 200
#define tabcolor 11
#define h_pointcolor 15
#define s_pointcolor 13
#define del_pointcolor 14
#define freecolor 4
#define strcolor 12
#define u_dpointhigh 25
#define wid 80
#define high 30
#define tabge 20
#define shannum 2
#define shanspeed 65535
#define autospeed 65535
typedef struct two
{
 struct two *before;
 int x;
 int y;
 int num;
 struct two *next;
 }twopoint;
int checkplaydemo()
{
 char choice;
again:
 printf("\n\nDo you want to look the Demo?[Y/N]\nPlease Enter:");
 choice=getche();
 getch();
 if(toupper(choice)=='Y')return 1;
 else if(toupper(choice)=='N')return 0;
 else {printf("\n\nEnter error! Please Enter again.\nPress any key to continue ...");
       goto again;
       }
 }
int pause(int fast)
{
  int esc;
  if(!fast)
 {
   if(kbhit())
    {
     esc=getch();
     if(esc==27)return 0;
     else delay(autospeed);
     }
   else
     delay(autospeed);
  }
return 1;
}
kuang(twopoint *p)
{
 int oldcolor;
 char numchar[10];
 oldcolor=getcolor();
 setcolor(tabcolor);
 rectangle(p->x,p->y,p->x+wid,p->y+high);
 line(p->x+(int)(7*wid/8.0),p->y+1,p->x+(int)(7*wid/8.0),p->y+high-1);
 line(p->x+(int)(wid/8.0),p->y+1,p->x+(int)(wid/8.0),p->y+high-1);

 sprintf(numchar,"%d",p->num);
 setcolor(2);
 if(p->x!=x0||p->y!=y0)outtextxy(p->x+(int)(wid/2.0)-(int)(textwidth(numchar)/2.0),p->y+13,numchar);
 else  outtextxy(p->x+(int)(wid/8.0)+13,p->y+13,"head");
 setcolor(oldcolor);
 }
/*headkuang(twopoint *p)
{
 int oldcolor;
 oldcolor=getcolor();
 setwritemode(1);
 p->x=x0;p->y=y0;
 kuang(p);
 setcolor(tabcolor);
 line(p->x+(int)(wid/2.0),p->y+1,p->x+(int)(wid/2.0),p->y+high-1);
 setcolor(4);
 outtextxy(p->x+(int)(wid/8.0)+13,p->y+13,"head");
 setcolor(oldcolor);
 } */
pointdown(twopoint *p,char str[])
{
 int oldcolor;
 oldcolor=getcolor();
 setcolor(s_pointcolor);
 setwritemode(1);
 line(p->x+(int)(wid/2.0),p->y-u_dpointhigh,p->x+(int)(wid/2.0),p->y-3);
 moveto(p->x+(int)(wid/2.0),p->y-3);
 lineto(p->x+(int)(wid/2.0)-3,p->y-11);
 lineto(p->x+(int)(wid/2.0),p->y-8);
 lineto(p->x+(int)(wid/2.0)+3,p->y-11);
 lineto(p->x+(int)(wid/2.0),p->y-3);
 setcolor(strcolor);
 if(strcmp(str,"Head")) settextstyle(2,0,7);
 outtextxy(p->x+(int)(wid/2.0)-(int)(textwidth(str)/2.0),p->y-u_dpointhigh-23,str);
 settextstyle(0,0,1);
 setwritemode(0);
 setcolor(oldcolor);
}
pointup(twopoint *p,char str[])
{
 int oldcolor;
 oldcolor=getcolor();
 setcolor(s_pointcolor);
 setwritemode(1);
 line(p->x+(int)(wid/2.0),p->y+high+u_dpointhigh,p->x+(int)(wid/2.0),p->y+high+3);
 moveto(p->x+(int)(wid/2.0),p->y+high+3);
 lineto(p->x+(int)(wid/2.0)-3,p->y+high+11);
 lineto(p->x+(int)(wid/2.0),p->y+high+8);
 lineto(p->x+(int)(wid/2.0)+3,p->y+high+11);
 lineto(p->x+(int)(wid/2.0),p->y+high+3);
 setcolor(strcolor);
 if(strcmp(str,"Head")) settextstyle(2,0,7);
 outtextxy(p->x+(int)(wid/2.0)-(int)(textwidth(str)/2.0),p->y+high+u_dpointhigh,str);
 settextstyle(0,0,1);
 setwritemode(0);
 setcolor(oldcolor);
}
pointnext(twopoint *p,int fast)
{
 int oldcolor,i,n;
 setwritemode(1);
 oldcolor=getcolor();
 setcolor(h_pointcolor);
 if(!fast)i=2*shannum+1;
 else i=1;
 for(n=1;n<=i;n++)
 {
 line(p->x+(int)(15*wid/16.0),p->y+(int)(high/4.0),p->x+wid+tabge+(int)(wid/16.0),p->y+(int)(high/4.0));
 moveto(p->x+wid+tabge+(int)(wid/16.0),p->y+(int)(high/4.0));
 lineto(p->x+wid+tabge+(int)(wid/16.0)-9,p->y+(int)(high/4.0)-2);
 lineto(p->x+wid+tabge+(int)(wid/16.0)-7,p->y+(int)(high/4.0));
 lineto(p->x+wid+tabge+(int)(wid/16.0)-9,p->y+(int)(high/4.0)+2);
 lineto(p->x+wid+tabge+(int)(wid/16.0),p->y+(int)(high/4.0));
 if(!fast)delay(shanspeed);
 }
 setcolor(oldcolor);
 setwritemode(0);
 }
pointbefore(twopoint *p,int fast)
{
 int oldcolor,i,n;
 setwritemode(1);
 oldcolor=getcolor();
 setcolor(h_pointcolor);
 if(!fast)i=2*shannum+1;
 else i=1;
 for(n=1;n<=i;n++)
 {
 line(p->x+wid+tabge+(int)(wid/16.0),p->y+(int)(3*high/4.0),p->x+(int)(15*wid/16.0),p->y+(int)(3*high/4.0));
 moveto(p->x+(int)(15*wid/16.0),p->y+(int)(3*high/4.0));
 lineto(p->x+(int)(15*wid/16.0)+9,p->y+(int)(3*high/4.0)-2);
 lineto(p->x+(int)(15*wid/16.0)+7,p->y+(int)(3*high/4.0));
 lineto(p->x+(int)(15*wid/16.0)+9,p->y+(int)(3*high/4.0)+2);
 lineto(p->x+(int)(15*wid/16.0),p->y+(int)(3*high/4.0));
 if(!fast)delay(shanspeed);
 }
 setcolor(oldcolor);
 setwritemode(0);
}

link_w_h(twopoint *head,twopoint *p,int fast)
{
 int oldcolor,i,n;
 setwritemode(1);
 oldcolor=getcolor();
 setcolor(h_pointcolor);
 if(!fast)i=2*shannum+1;
 else i=1;
 for(n=1;n<=i;n++)
{ line(p->x+(int)(15*wid/16.0),p->y+(int)(high/4.0),p->x+wid+tabge,p->y+(int)(high/4.0));
 moveto(p->x+wid+tabge,p->y+(int)(high/4.0));
 lineto(p->x+wid+tabge,p->y+2*high);
 lineto(head->x-tabge,p->y+2*high);
 lineto(head->x-tabge,p->y+(int)(high/4.0));
 lineto(head->x+(int)(wid/16.0),p->y+(int)(high/4.0));
 lineto(head->x+(int)(wid/16.0)-9,head->y+(int)(high/4.0)-2);
 lineto(head->x+(int)(wid/16.0)-7,head->y+(int)(high/4.0));
 lineto(head->x+(int)(wid/16.0)-9,head->y+(int)(high/4.0)+2);
 lineto(head->x+(int)(wid/16.0),head->y+(int)(high/4.0));
 if(!fast)delay(shanspeed);
 }
 setcolor(oldcolor);
 setwritemode(0);
}
link_h_w(twopoint *head,twopoint *p,int fast)
{
 int oldcolor,i,n;
 setwritemode(1);
 oldcolor=getcolor();
 setcolor(h_pointcolor);
 if(!fast)i=2*shannum+1;
 else i=1;
 for(n=1;n<=i;n++)
{ line(p->x+(int)(15*wid/16.0),p->y+(int)(3*high/4.0),p->x+wid+(int)(2*tabge/5.0),p->y+(int)(3*high/4.0));
 moveto(p->x+wid+(int)(2*tabge/5.0),p->y+(int)(3*high/4.0));
 lineto(p->x+wid+(int)(2*tabge/5.0),p->y+high+(int)(high/2.0));
 lineto(head->x-(int)(2*tabge/5.0),p->y+high+(int)(high/2.0));
 lineto(head->x-(int)(2*tabge/5.0),p->y+(int)(3*high/4.0));
 lineto(head->x+(int)(wid/16.0),p->y+(int)(3*high/4.0));
 moveto(p->x+(int)(15*wid/16.0),p->y+(int)(3*high/4.0));
 lineto(p->x+(int)(15*wid/16.0)+9,p->y+(int)(3*high/4.0)-2);
 lineto(p->x+(int)(15*wid/16.0)+7,p->y+(int)(3*high/4.0));
 lineto(p->x+(int)(15*wid/16.0)+9,p->y+(int)(3*high/4.0)+2);
 lineto(p->x+(int)(15*wid/16.0),p->y+(int)(3*high/4.0));
 if(!fast)delay(shanspeed);
 }
 setcolor(oldcolor);
 setwritemode(0);
 }
int creatchaindemo(twopoint *head,int fast)
{
 twopoint *p,*q;
 int n=0;
 p=head;
 q=NULL;
 setbkcolor(1);
 if(!pause(fast))return 0;
 kuang(head);
 pointdown(head,"Head");
 if(!pause(fast))return 0;
 pointup(p,"p");
while(p->next!=head)
 {n++;
  getch();
  if(!pause(fast))return 0;
  if(n!=1)pointdown(q,"q");
  q=p->next;
  kuang(q);
  pointdown(q,"q");
  if(!pause(fast))return 0;
  pointnext(p,fast);
  if(!pause(fast))return 0;
  pointbefore(p,fast);
  if(!pause(fast))return 0;
  pointup(p,"p");
  p=q;
  pointup(p,"p");
  }
 if(!pause(fast))return 0;
 link_w_h(head,p,fast);
 if(!pause(fast))return 0;
 link_h_w(head,p,fast);
 return 1;
}

deleltedemo(twopoint *head,int n)
{
 twopoint *p;
 int i,oldcolor;
 p=head;
 oldcolor=getcolor();
 pointup(head->before,"p");
 pointdown(head->before,"q");
 pointup(p,"p");
 if(!pause(0))return;
 for(i=1;i<=n;i++)
 {
  pointup(p,"p");
  p=p->next;
  if(!pause(0))return;
  pointup(p,"p");
  if(!pause(0))return;
  }
 if(!pause(0))return;
 pointnext(p->before,0);
 if(!pause(0))return;
 setwritemode(1);
 setcolor(del_pointcolor);
 for(i=1;i<=2*shannum+1;i++)
{ if(i==2*shannum+1)setwritemode(0);
 line(p->before->x+(int)(15*wid/16.0),p->before->y+(int)(high/4.0),p->before->x+wid+(int)(tabge/3.0),p->before->y+(int)(high/4.0));
 moveto(p->before->x+wid+(int)(tabge/3.0),p->before->y+(int)(high/4.0));
 lineto(p->before->x+wid+(int)(tabge/3.0),p->before->y-(int)(2*high/3.0));
 lineto(p->next->x-tabge/3,p->next->y-(int)(2*high/3.0));
 lineto(p->next->x-tabge/3,p->next->y+(int)(high/4.0));
if(i==1)
{ setcolor(h_pointcolor);
 lineto(p->next->x+wid/16.0,p->next->y+(int)(high/4.0));
 lineto(p->next->x+(int)(wid/16.0)-9,p->next->y+(int)(high/4.0)-2);
 lineto(p->next->x+(int)(wid/16.0)-7,p->next->y+(int)(high/4.0));
 lineto(p->next->x+(int)(wid/16.0)-9,p->next->y+(int)(high/4.0)+2);
 lineto(p->next->x+(int)(wid/16.0),p->next->y+(int)(high/4.0));
 }
 setcolor(del_pointcolor);
 moveto(p->next->x-tabge/3,p->next->y+(int)(high/4.0));
 lineto(p->next->x+wid/16.0,p->next->y+(int)(high/4.0));
 lineto(p->next->x+(int)(wid/16.0)-9,p->next->y+(int)(high/4.0)-2);
 lineto(p->next->x+(int)(wid/16.0)-7,p->next->y+(int)(high/4.0));
 lineto(p->next->x+(int)(wid/16.0)-9,p->next->y+(int)(high/4.0)+2);
 lineto(p->next->x+(int)(wid/16.0),p->next->y+(int)(high/4.0));
 delay(shanspeed);
 }
 if(!pause(0))return;
 if(p->next==head)link_h_w(head,p,0);
 else pointbefore(p,0);
 if(!pause(0))return;
 setwritemode(1);
 for(i=1;i<=2*shannum+1;i++)
{ if(i==2*shannum+1)setwritemode(0);
 line(p->next->x+(int)(wid/16.0),p->next->y+(int)(3*high/4.0),p->next->x-(int)(2*tabge/3.0),p->next->y+(int)(3*high/4.0));
 moveto(p->next->x-(int)(2*tabge/3.0),p->next->y+(int)(3*high/4.0));
 lineto(p->next->x-(int)(2*tabge/3.0),p->next->y-(int)(high/3.0));

 lineto(p->before->x+wid+(int)(2*tabge/3.0),p->before->y-(int)(high/3.0));
 lineto(p->before->x+wid+(int)(2*tabge/3.0),p->before->y+(int)(3*high/4.0));
if(i==1)
{ setcolor(h_pointcolor);
 lineto(p->before->x+(int)(15*wid/16.0),p->before->y+(int)(3*high/4.0));
 lineto(p->before->x+(int)(15*wid/16.0)+9,p->before->y+(int)(3*high/4.0)-2);
 lineto(p->before->x+(int)(15*wid/16.0)+7,p->before->y+(int)(3*high/4.0));
 lineto(p->before->x+(int)(15*wid/16.0)+9,p->before->y+(int)(3*high/4.0)+2);
 lineto(p->before->x+(int)(15*wid/16.0),p->before->y+(int)(3*high/4.0));
 }
 setcolor(del_pointcolor);
 moveto(p->before->x+wid+(int)(2*tabge/3.0),p->before->y+(int)(3*high/4.0));
 lineto(p->before->x+(int)(15*wid/16.0),p->before->y+(int)(3*high/4.0));
 lineto(p->before->x+(int)(15*wid/16.0)+9,p->before->y+(int)(3*high/4.0)-2);
 lineto(p->before->x+(int)(15*wid/16.0)+7,p->before->y+(int)(3*high/4.0));
 lineto(p->before->x+(int)(15*wid/16.0)+9,p->before->y+(int)(3*high/4.0)+2);
 lineto(p->before->x+(int)(15*wid/16.0),p->before->y+(int)(3*high/4.0));
 delay(shanspeed);
 }
 setwritemode(1);
 setcolor(h_pointcolor);

 if(!pause(0))return;
 for(i=1;i<=2*shannum+1;i++)
 { line(p->x+(int)(wid/16.0),p->y+(int)(3*high/4.0),p->x-(int)(tabge/3.0),p->y+(int)(3*high/4.0));
  delay(shanspeed);
  }
 if(!pause(0))return;
 for(i=1;i<=2*shannum+1;i++)
 { line(p->x+(int)(15*wid/16.0),p->y+(int)(high/4.0),p->x+wid+(int)(2*tabge/3.0),p->y+(int)(high/4.0));
  delay(shanspeed);
  }
 setwritemode(0);
 setcolor(del_pointcolor);
 line(p->x+wid+tabge/3.0+1,p->y-high/3.0,p->x+wid+tabge/3.0+1,p->y+3*high/4.0);

 if(!pause(0))return;
 setcolor(freecolor);
 arc(p->x+wid,p->y,90,190,wid/2.0);
 moveto(p->x+wid,p->y-(int)(wid/2.0));
 lineto(p->x+wid-9,p->y-(int)(wid/2.0)-2);
 lineto(p->x+wid-7,p->y-(int)(wid/2.0));
 lineto(p->x+wid-9,p->y-(int)(wid/2.0)+2);
 lineto(p->x+wid,p->y-(int)(wid/2.0));

 setcolor(strcolor);
 outtextxy(p->x+wid-textwidth("free")/2.0,p->y-(int)(wid/2.0)-15,"free");
 setcolor(oldcolor);
 setwritemode(0);
}


outputchain(twopoint *head)
{
 twopoint *p;
 int nextorbefore;
again:
 clrscr();
 printf("------Output the chain------\nFor next or For before output?[N/B]\nPlease Enter:");
 nextorbefore=getche();
 getch();

 if(tolower(nextorbefore)=='n')
  {
  printf("\n\t\b\bp -> num\n");
  p=head->next;
  while(p!=head)
  {
   printf("\n\t%d\n",p->num);
   p=p->next;
   }
  }
 else if(tolower(nextorbefore)=='b')
 {
  printf("\n\t\b\bp -> num\n");
  p=head->before;
  while(p!=head)
  {
   printf("\n\t%d\n",p->num);
   p=p->before;
   }
  }
 else {printf("\n\nEnter error! Please enter again.\nPress any key to continue ...");getch();goto again;}
printf("\nPress any key to continue ...");
getch();
}
creatchain(twopoint *head)
{
 twopoint *p,*q;
 int n=1,allnum;
 head->x=x0;
 head->y=y0;
 p=head;
 q=NULL;
again:
 clrscr();
 printf("----------Creat chain----------\nPlease Enter the point num( num<=5 ).\nnum=");
 scanf("%d",&allnum);
 if(allnum<=0||allnum>5){printf("The number is full!Enter again.");getch();goto again;}
 printf("\nPlease enter the value(int) of every point.");
 for(n=1;n<=allnum;n++)
 {
  q=(twopoint *)malloc(sizeof(twopoint));
  printf("\nPoint %d: ",n);
  scanf("%d",&q->num);
  q->x=x0+n*(wid+tabge);
  q->y=y0;
  p->next=q;
  q->before=p;
  p=q;
  }
 p->next=head;
 head->before=p;
 printf("The chain has been created!It will be Displayed.\nPress any key to continue ...\n");
 getch();
}
int delete(twopoint *head)
{
 twopoint *p,*q;
 int n,i,mx,my,nx,ny;
again:
 p=head;
 clrscr();
 printf("---------- Delete a point ----------\nPlease Enter the deleted point:");
 scanf("%d",&n);
 for(i=1;i<=n;i++)
 { p=p->next;
  if(p==head)
  { printf("The number %d is wrong!Please enter again.\nPress any key to continue ...",n);
   getch();
   goto again;
  }
 }
 p->before->next=p->next;
 p->next->before=p->before;
 q=p;
 mx=q->x;
 my=q->y;
 while(1)
 { nx=q->next->x;ny=q->next->y;
   q->next->x=mx;q->next->y=my;
   q=q->next;
  if(q->next==head)break;
   mx=q->next->x;my=q->next->y;
   q->next->x=nx;q->next->y=ny;
   q=q->next;
  if(q->next==head)break;
  }
 p->before=NULL;
 p->next=NULL;
 free(p);
 printf("\n\nThe %dth point has been deleted,it will display the chain.\nPress any key continue ...",n);
 getch();
 return n;
 }
int insert(twopoint *head)
{
 twopoint *p,*q;
 int n,i;
 p=head;
 q=(twopoint *)malloc(sizeof(twopoint));
 clrscr();
 printf("---------- Insert a point ---------\n");
 printf("Enter the insert address:");
 scanf("%d",&n);
 printf("\nand the number:");
 scanf("%d",&q->num);
 for(i=1;i<=n;i++)p=p->next;
 q->x=p->x-(int)((tabge+wid)/2.0);
 q->y=p->y-2*high;

 p->before->next=q;
 q->before=p->before;
 q->next=p;
 p->before=q;
 printf("\n\nThe point before %dth point has been inserted,it will display the chain.\nPress any key continue ...",n);
 getch();
 return n;
 }
copychain(twopoint *midhead,twopoint *head)
{
 twopoint *p,*m,*n;
 p=head->next;
 m=midhead;
 midhead->x=head->x;
 midhead->y=head->y;
 while(p!=head)
 {
  n=(twopoint *)malloc(sizeof(twopoint));
  n->x=p->x;
  n->y=p->y;
  n->num=p->num;
  m->next=n;n->before=m;
  m=n;
  p=p->next;
  }
 m->next=midhead;
 midhead->before=m;
}


 main()
{
 twopoint chainhead,*head=&chainhead;
 twopoint midchainhead,*midhead=&midchainhead;
 int gd=0,gm=1;
 int n;
  initgraph(&gd,&gm,"");

  restorecrtmode();
  creatchain(head);
  outputchain(head);
  if(checkplaydemo())
   {setgraphmode(2);if(creatchaindemo(head,0))getch();}

  restorecrtmode();
  copychain(midhead,head);
  n=delete(head);
  outputchain(head);
  if(checkplaydemo())
   {setgraphmode(2);
    creatchaindemo(midhead,1);deleltedemo(midhead,n);getch();}
    cleardevice();
    creatchaindemo(head,1);
    getch();
/*  restorecrtmode();
  copychain(midhead,head);
  n=insert(head);
   outputchain(midhead);
  outputchain(head);
  outputchain(midhead);
/*  if(checkplaydemo())
   {setgraphmode(2);
    creatchaindemo(midhead,1);insertdemo(midhead,n);}*/*/
 }
搜索更多相关主题的帖子: java 
2011-02-28 17:10
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
收藏
得分:0 
有种......的冲动!绝对前无古人,后无来者!!!!!

   唯实惟新 至诚致志
2011-02-28 19:17
jc184892058
Rank: 2
等 级:论坛游民
帖 子:7
专家分:20
注 册:2010-12-2
收藏
得分:0 
呵呵  自己完成了  而且不可能直接类似翻译的哦   还是得按要求从编
2011-03-02 18:32
gdy0349
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:上海
等 级:版主
威 望:11
帖 子:223
专家分:676
注 册:2008-11-12
收藏
得分:0 
我今天才看到,楼主实在是太NX了
2011-03-03 19:55
晓鹤
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-2-24
收藏
得分:0 
lz实在是............
2011-03-04 13:39
快速回复:c改成java 双向链表的图形分步演示 哪位大哥帮帮忙 谢谢了!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.038320 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved