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

📄 listdlg.cpp

📁 数据结构课程设计!MFC做的! 其中有个是链表(单链表
💻 CPP
📖 第 1 页 / 共 2 页
字号:
      q=p->next;p->next=q->next;
	  e=q->data;free(q);
	  length--;
	  return e;
	 }
 }     


void CListDlg::Draw_1()
{  
	// TODO: Add your control notification handler code here
	
	CListDlg::Invalidate();
	CListDlg::UpdateWindow();
	CDC	*pDC = GetDC();
	CClientDC dc(this);
	CPen	pen;
	CString s;
	int tx=60,ty=70,ttime=40;
	int x0,y0,R0;
	x0=250;y0=300;R0=150;
	int R1=100;
	int xx1,yy1;
	int x1,y1,pror_x,pror_y,degree,time;
	time=360/length;
	degree=0;
	pror_x=(int)(x0+R0*cos(degree*3.14/180));
	pror_y=(int)(y0+R0*sin(degree*3.14/180));
	pen.CreatePen(PS_SOLID, 1, RGB(255, 0, 0));			
	dc.SelectObject(pen);
    CRect rect;   	
	pDC->SetBkColor(RGB(255,255,255));
	LinkList p;p=L->next;
	int sTep;sTep=1;CString ss;
    for(int k1=0;k1<length;k1++)
	{
	 x1=(int)(x0+R0*cos(degree*3.14/180));
	 y1=(int)(y0+R0*sin(degree*3.14/180));
	 xx1=(int)(x0+R1*cos(degree*3.14/180));
	 yy1=(int)(y0+R1*sin(degree*3.14/180));
	rect.bottom = y1 - R;
	rect.top	= y1 + R;
	rect.left	= x1 - R;
	rect.right	= x1 + R;
	pDC->Ellipse(rect);
	s.Format("%d",p->data);
	pDC->TextOut(tx,ty,s);
	tx+=ttime;
	pDC->TextOut(x1,y1,s);
	ss.Format("%d",sTep);
	pDC->SetBkColor(RGB(255,255,0));
	pDC->TextOut(xx1,yy1,ss);
    pDC->SetBkColor(RGB(255,255,255));
	dc.MoveTo(pror_x,pror_y);
	dc.LineTo(x1,y1);
	degree+=time;
	pror_x=x1;
	pror_y=y1;
	p=p->next;
	sTep++;
	Sleep(300);
	}	
	ReleaseDC(pDC);	
	
}
////////////////////////////////////////////////////////////////////
//循环链表操作
void Creat_huanlist(LinkList &L2)
{  int i;int j;LinkList p;
   i=j=0;
   StringToInt(st);
   L2=(LinkList)malloc(sizeof(LNode));
   L2->next=L2;L2->data=length;
   for(;i<length;i++)
   { p=(LinkList)malloc(sizeof(LNode));
     p->next=L2->next;
	 L2->next=p;
	 p->data=e[j++];
   }
}

void Insert_hunalist(LinkList &L2)
{   LinkList p,q;int i=1; 
    p=L2; 
	if(Pos<1||Pos>length+1)
    {MessageBox(NULL,"插入错误!!超出范围,请重新输入!!","插入错误!!超出范围,请重新输入!!",MB_OK);
	return;}
    for(;i<Pos;i++)p=p->next;
    q=(LinkList)malloc(sizeof(LNode));
	q->data=inSert;
	q->next=p->next;
	p->next=q;
	length++;
}

void Delet_huanlist(LinkList &L)
{  LinkList p;int i=1;
   p=L2;
   if(delet<1||delet>length)
   {MessageBox(NULL,"删除错误!!超出范围,请重新输入!!","删除错误!!超出范围,请重新输入!!",MB_OK);
   return;}
   for(;i<Pos;i++)p=p->next;
   p=p->next;
   length--;
}


void CListDlg::Draw_2()
{   CString s;
	int x1,y1,xx1,yy1;int i;
    xx1=250;yy1=300;int time;
	int tx=60,ty=70,ttime=40;
	int pror_x;int pror_y;
	int RR=150;
	int degree=0;
	int R1=100;
	int xx2,yy2;
	time=360/length;
	pror_x=(int)(xx1+RR*cos(degree*3.14/180));
    pror_y=(int)(yy1+RR*sin(degree*3.14/180));
	CListDlg::Invalidate();
	CListDlg::UpdateWindow();
	CDC	*pDC = GetDC();
	CClientDC dc(this);
	CPen pen;CRect rect;LinkList p;
	p=L2->next;
	pen.CreatePen(PS_SOLID, 1, RGB(255, 0, 0));			
	dc.SelectObject(pen);
	int sTep;CString ss;sTep=1;
	for(i=0;i<length;i++)
	{ x1=(int)(xx1+RR*cos(degree*3.14/180));
	  y1=(int)(yy1+RR*sin(degree*3.14/180));
	  xx2=(int)(xx1+R1*cos(degree*3.14/180));
	  yy2=(int)(yy1+R1*sin(degree*3.14/180));
	  rect.bottom =   y1 - R;
	  rect.top	  =   y1 + R;
	  rect.left	  =   x1 - R;
	  rect.right  =   x1 + R;
	  pDC->Ellipse(rect);
	  s.Format("%d",p->data);
	  pDC->TextOut(x1,y1,s);
	  ss.Format("%d",sTep);
	  pDC->TextOut(tx,ty,s);
	  tx+=ttime;
	  pDC->SetBkColor(RGB(255,255,0));
	  pDC->TextOut(xx2,yy2,ss);
	  pDC->SetBkColor(RGB(255,255,255));
	  sTep++;
	  dc.MoveTo(pror_x,pror_y);
	  dc.LineTo(x1,y1);
	  degree+=time;
	  p=p->next;
	  pror_x=x1;
	  pror_y=y1;
	  Sleep(300);
	}
    pror_x=(int)(xx1+RR*cos(degree*3.14/180));
    pror_y=(int)(yy1+RR*sin(degree*3.14/180));
	dc.MoveTo(x1,y1);
	dc.LineTo(pror_x,pror_y);
	
	ReleaseDC(pDC);	
}


//////////////////////////////////////////////////////////////////
// 双向链表操作

void CreateList_DL(LinkList &L3)
{  LinkList p;int i=0;int j=0;
   StringToInt(st);
   L3=(LinkList)malloc(sizeof(LNode));
   L3->next=NULL;L3->pror=NULL;
   for(;i<length;i++,j++)
   {
		p=(LinkList)malloc(sizeof(LNode));
	    p->data=e[j];
		p->next=L3->next;L3->next=p;
	    p->pror=L3;if(j!=0)p->next->pror=p;
   }
} 


int  ListInsert_DL(LinkList &L3,int i,int e)
{
	   LinkList p,s;p=L3;int j=0;
	   if(i>length+1||i<1)
	   {MessageBox(NULL,"插入错误!!超出范围,请重新输入!!","插入错误!!超出范围,请重新输入!!",MB_OK);
	   return ERROR;}
	   else{
       while(p&&j<i-1){p=p->next;j++;}
	   if(!p||j>i-1)
	   {MessageBox(NULL,"插入错误!!超出范围,请重新输入!!","插入错误!!超出范围,请重新输入!!",MB_OK);
	   return ERROR;}
       s=(LinkList)malloc(sizeof(LNode));
	   s->data=e;s->next=p->next;
	   p->next=s;
	   s->pror=p;
	   if(i!=length+1)
	   s->next->pror=s;
	   length++;
	   return OK;
	   }
}          

int  ListDelete_DL(LinkList &L3,int i)
{    int e;
	 LinkList p,q;p=L3;int j=0;
	 if(i>length||i<1)
	   {MessageBox(NULL,"删除错误!!超出范围,请重新输入!!","删除错误!!超出范围,请重新输入!!",MB_OK);
	   return ERROR;
	   }
	 else{
	 while(p->next&&j<i-1){p=p->next;++j;}
	 if(!(p->next)||j>i-1)
	 {MessageBox(NULL,"删除错误!!超出范围,请重新输入!!","删除错误!!超出范围,请重新输入!!",MB_OK);
	   return ERROR;
	   }
	 else
	 {
      q=p->next;p->next=q->next;
	  if(i!=length)
	  q->next->pror=p;
	  e=q->data;free(q);
	  length--;
	  return e;
	 }
	 }
 }     


void CListDlg::Draw_3()
{  
	// TODO: Add your control notification handler code here
    CListDlg::Invalidate();
	CListDlg::UpdateWindow();
	CDC	*pDC = GetDC();
	CClientDC dc(this);
	CString s3;
	CPoint p1,p2;
	int x1,y1;
	int x0=250;int y0=300;
	int R0=140;
	int degree,time;
	int pror_x;
	int pror_y;
	int tx=60,ty=70,ttime=40;
	int xx1,yy1,R1;R1=100;
	degree=0;
	pror_x=(int)(x0+R0*cos(degree*3.14/180));
	pror_y=(int)(y0+R0*sin(degree*3.14/180));
	time=360/length;
	CPen	pen;
	pen.CreatePen(PS_SOLID, 1, RGB(255, 0, 0));			
	dc.SelectObject(pen);
    CRect rect;   
	LinkList p;p=L3->next;
	pDC->SetBkColor(RGB(255,255,255));
	int sTep;sTep=1;CString ss;
    for(int k1=0;k1<length;k1++)
	{ 
	 x1=(int)(x0+R0*cos(degree*3.14/180));
	 y1=(int)(y0+R0*sin(degree*3.14/180));
	 xx1=(int)(x0+R1*cos(degree*3.14/180));
	 yy1=(int)(y0+R1*sin(degree*3.14/180));
     rect.bottom= y1 - R;
	 rect.top	= y1 + R;
	 rect.left	= x1 - R;
	 rect.right	= x1 + R;
	 pDC->Ellipse(rect);
	 ss.Format("%d",sTep);
	 pDC->SetBkColor(RGB(255,255,0));
	 pDC->TextOut(xx1,yy1,ss);
	 pDC->SetBkColor(RGB(255,255,255));
	 //dc.MoveTo(pror_x+R,pror_y);
	 //dc.LineTo(x1+R,y1);
	 //dc.MoveTo(pror_x-R,pror_y);
	 //dc.LineTo(x1-R,y1);
	 p1.x=pror_x;
	 p1.y=pror_y;
	 p2.x=x1;
	 p2.y=y1;
	 DrawArc(p1,p2,1);
	 DrawArc(p1,p2,-1);
	 s3.Format("%d",p->data);
	 pDC->TextOut(x1,y1,s3);
	 pDC->TextOut(tx,ty,s3);
	 tx+=ttime;
	 p=p->next;
	 pror_x=x1;
	 pror_y=y1;
     degree+=time;
	 sTep++;
	 Sleep(300);
	}
	ReleaseDC(pDC);		
}


///////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////
void CListDlg::OnRadio1() 
{
	// TODO: Add your control notification handler code here
	UpdateData(FALSE);
	Invalidate();
	i=0;
    kind=dan;
	
}
void CListDlg::OnRadio2() 
{
	// TODO: Add your control notification handler code here
	UpdateData(FALSE);
	Invalidate();
	i=0;
	kind=xun;
	
}

void CListDlg::OnRadio3() 
{
	// TODO: Add your control notification handler code here
	UpdateData(FALSE);
	Invalidate();
	i=0;
	kind=shuang;
	
}


void CListDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	switch(kind)
	{  case dan: CreateList_L(L);CListDlg::Draw_1();break;
	   case xun: Creat_huanlist(L2);CListDlg::Draw_2();break;
	   case shuang: CreateList_DL(L3);CListDlg::Draw_3();break;
	}

	
}
void CListDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
	int i,e;i=Pos;e=inSert;int ll;
	ll=length;
	switch(kind)
	{  case dan: ListInsert_L(L,i,e);if(ll!=length)CListDlg::Draw_1();break;
	   case xun: Insert_hunalist(L2);if(ll!=length)CListDlg::Draw_2();break;
	   case shuang:ListInsert_DL(L3,i,e);if(ll!=length)CListDlg::Draw_3();break;
	}
}

void CListDlg::OnButton3() 
{
	// TODO: Add your control notification handler code here
	int i;i=delet;
	int ll=length;
	switch(kind)
	{  case dan: ListDelete_L(L,i);if(ll!=length)CListDlg::Draw_1();break;
	   case xun: Delet_huanlist(L2);if(ll!=length)CListDlg::Draw_2();break;
	   case shuang:ListDelete_DL(L3,i);if(ll!=length)CListDlg::Draw_3();break;
	}
}
////////////////////////////////////////////////////////////////
////My Code End 
/////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

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