import sys
class equation:
def __init__(self):
self.coef=0
self.exp=0
self.next=None
def create_link(data):
for i in range(4):
newnode=equation()
if not newnode:
print('Error!!内存分配失败!!')
sys.exit(0)
if i==0:
newnode.coef=data[i]
newnode.exp=3-i
newnode.next=None
head=newnode
ptr=head
elif data[i]!=0:
newnode.coef=data[i]
newnode.exp=3-i
newnode.next=None
ptr.next=newnode
ptr=newnode
return head
def print_link(head):
while head!=None:
if head.exp==1 and head.coef!=0:
print('%dX&#
数据结构与算法(python)单向链表表示两个多项式相加
最新推荐文章于 2023-07-17 16:03:38 发布