데이터 구조일원 여러 차례 방정식 의 표시 와 더하기

1745 단어 데이터 구조
#include 
#include 
#include 
using namespace std;
typedef struct  polynomial
{
	int factor;//  
	int indice;//  
	struct polynomial *next;
}polynomial,*LinkList;
//   --    
void CreateLink(LinkList &L, int n)
{
	LinkList p,s;
	int i;
	L = (LinkList)malloc(sizeof(polynomial));
	L->next = NULL;
	p = L;
	for (i = 0; i < n; i++)
	{
		s = (LinkList)malloc(sizeof(polynomial));
		cout<>s->factor>>s->indice;
		s->next = NULL;
		p->next = s;
		p = s;
	}
}
//     (         )
void AddList(LinkList List1, LinkList List2, LinkList &L)
{
	LinkList p1,p2,list,s;
	L = (LinkList)malloc(sizeof(polynomial));
	L->next = NULL;
	list = L;
	p1 = List1->next;
	p2 = List2->next;
	while (p1 && p2)
	{
		if (p1->indice < p2->indice)
		{
			s = p1->next;
			list->next = p1;
			list = p1;
			list->next = NULL;//              
			p1 = s;
		}
		else if (p1->indice == p2->indice)
		{
			p1->factor = p1->factor + p2->factor;
			if (p1->factor != 0)//     0
			{
				list->next = p1;
				s = p1->next;
				list = p1;
				list->next = NULL;//              
				p1 = s;
				p2 = p2->next;
			} 
			else //    0
			{
				p1 = p1->next;
				p2 = p2->next;
			}
			
		}
		else
		{
			s = p2->next;
			list->next = p2;
			list = p2;
			list->next = NULL;
			p2 = s;
		}
	}
	if(p1 != NULL) list->next = p1;
	if(p2 != NULL) list->next = p2;
}
//    
void VisitList(LinkList L)
{
	LinkList p;
	p = L->next;
	if (p==NULL)
	{
		cout<factor<indice;
		p = p->next;
		if(p != NULL)
			cout<>n;
	CreateLink(p,n);
	cout<>m;
	CreateLink(q,m);
	cout<

좋은 웹페이지 즐겨찾기