📄 form1.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using List;
namespace WindowsApplication3
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label lblOut;
private Clist La;
private Clist Lb;
private Polynomial Pa;
private Polynomial Pb;
private System.Windows.Forms.Label lbl_a;
private System.Windows.Forms.Label lbl_b;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
/// <summary>
/// 初始化链表
/// </summary>
public void CreateList()
{
La=new Clist();
La.AppendNode(3);
La.AppendNode(5);
La.AppendNode(8);
La.AppendNode(11);
Lb=new Clist();
Lb.AppendNode(2);
Lb.AppendNode(6);
Lb.AppendNode(8);
Lb.AppendNode(9);
Lb.AppendNode(11);
Lb.AppendNode(15);
Lb.AppendNode(20);
return;
}
/// <summary>
/// 初始化多项式
/// </summary>
public void CreatePoly()
{
Pa=new Polynomial();
Pa.AppendNode(0,7);
Pa.AppendNode(1,3);
Pa.AppendNode(8,9);
Pa.AppendNode(17,5);
Pb=new Polynomial();
Pb.AppendNode(1,8);
Pb.AppendNode(7,22);
Pb.AppendNode(8,9);
}
/// <summary>
/// 算法2.1
/// </summary>
public string ex2_1()
{
Clist temp;
int La_len,Lb_len,i,e;
//CreateList();
La_len=La.ListLength;
Lb_len=Lb.ListLength;
temp=La;
for(i=1;i<=Lb_len;i++)
{
e=Lb.GetElem(i);
if(!temp.Isin(e))
{
La.ListInsert(La_len,e);
}
}
return La.PrintList();
}
/// <summary>
/// 算法2.2
/// </summary>
public string ex2_2()
{
Clist Lc=new Clist();
int La_len,Lb_len,i,j;
int ai,bj;
//int k;
i=j=1;
//k=0;
La_len=La.ListLength;
Lb_len=Lb.ListLength;
while((i<=La_len) && (j<=Lb_len))
{
ai=La.GetElem(i);
bj=Lb.GetElem(j);
if(ai<=bj)
{
//Lc.ListInsert(k++,ai);
Lc.AppendNode(ai);
++i;
}
else
{
//Lc.ListInsert(k++,bj);
Lc.AppendNode(bj);
++j;
}
}
while(i<=La_len)
{
ai=La.GetElem(i);
//Lc.ListInsert(k++,ai);
i++;
Lc.AppendNode(ai);
}
while(j<=Lb_len)
{
bj=Lb.GetElem(j);
//Lc.ListInsert(k++,bj);
Lc.AppendNode(bj);
j++;
}
return Lc.PrintList();
}
/// <summary>
/// 算法2.23多项式相加
/// </summary>
public string AddPoly()
{
int exp_a,exp_b;
float coef_a,coef_b;
Pa.MoveFirst();
Pb.MoveFirst();
while(!Pa.IsEof() && !Pb.IsEof())
{
exp_a=Pa.ThisValue();
exp_b=Pb.ThisValue();
coef_a=Pa.ThisCoef();
coef_b=Pb.ThisCoef();
if(exp_a<exp_b)
{
Pa.MoveNext();
}
if(exp_a==exp_b)
{
Pa.SetCoef(coef_a+coef_b);
Pa.MoveNext();
Pb.MoveNext();
}
if(exp_a>exp_b)
{
Pa.ListInsert(exp_b,coef_b);
Pb.MoveNext();
}
}
return Pa.PrintList();
}
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.lblOut = new System.Windows.Forms.Label();
this.lbl_a = new System.Windows.Forms.Label();
this.lbl_b = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// lblOut
//
this.lblOut.Location = new System.Drawing.Point(88, 112);
this.lblOut.Name = "lblOut";
this.lblOut.Size = new System.Drawing.Size(256, 24);
this.lblOut.TabIndex = 0;
//
// lbl_a
//
this.lbl_a.Location = new System.Drawing.Point(88, 32);
this.lbl_a.Name = "lbl_a";
this.lbl_a.Size = new System.Drawing.Size(256, 23);
this.lbl_a.TabIndex = 1;
//
// lbl_b
//
this.lbl_b.Location = new System.Drawing.Point(88, 72);
this.lbl_b.Name = "lbl_b";
this.lbl_b.Size = new System.Drawing.Size(256, 23);
this.lbl_b.TabIndex = 1;
//
// button1
//
this.button1.Location = new System.Drawing.Point(24, 168);
this.button1.Name = "button1";
this.button1.TabIndex = 2;
this.button1.Text = "算法2.1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label1
//
this.label1.Location = new System.Drawing.Point(24, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(48, 23);
this.label1.TabIndex = 3;
this.label1.Text = "链表A";
//
// label2
//
this.label2.Location = new System.Drawing.Point(24, 72);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(48, 23);
this.label2.TabIndex = 4;
this.label2.Text = "链表B";
//
// label3
//
this.label3.Location = new System.Drawing.Point(24, 112);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(48, 23);
this.label3.TabIndex = 4;
this.label3.Text = "结果";
//
// button2
//
this.button2.Location = new System.Drawing.Point(120, 168);
this.button2.Name = "button2";
this.button2.TabIndex = 5;
this.button2.Text = "算法2.2";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(224, 168);
this.button3.Name = "button3";
this.button3.TabIndex = 5;
this.button3.Text = "算法2.23";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(440, 273);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button2,
this.label2,
this.label1,
this.button1,
this.lbl_a,
this.lblOut,
this.lbl_b,
this.label3,
this.button3});
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
private void button1_Click(object sender, System.EventArgs e)
{
CreateList();
lbl_a.Text =La.PrintList();
lbl_b.Text =Lb.PrintList();
lblOut.Text =ex2_1();
}
private void button2_Click(object sender, System.EventArgs e)
{
CreateList();
lbl_a.Text =La.PrintList();
lbl_b.Text =Lb.PrintList();
lblOut.Text=ex2_2();
}
private void button3_Click(object sender, System.EventArgs e)
{
CreatePoly();
lbl_a.Text =Pa.PrintList();
lbl_b.Text =Pb.PrintList();
lblOut.Text=AddPoly();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -