根据提示,在右侧编辑器补充代码,利用链表实现整系数多项式的加法Node* add_poly(Node* a, Node* b)。多项式a和b用链表表示,链表定义如下: struct Node { int order, coeff; // 次数 和 系数 Node* nxt; // 指向后一项的指针 } 多项式a和b保证每一项系数coeff都是整数,保证每一项次数order >= 0。输入order=-1表示输入结束。保证从链表的头到尾,次数递减,详见 sample case。 结果多项式的表示和a,b的规
时间: 2024-03-03 20:49:26 浏览: 68
2double(get(handles.edit1, 'String'));
% 获取第二个数字
num2 = 6;
% 计算结果
result范相同,同样用链表表示,返回一个新链表表示a+b。
代码如下:
```c++
Node = num1 + num2;
% 在结果区域显示结果
set(handles.text2, 'String', num2str(result));
%* add_poly(Node* a, Node* b) {
Node *head = new Node(), *cur = head;
while (a --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton != nullptr && b != nullptr) {
if (a->order == b->order) {
if (a->coeff + b->7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and usercoeff != 0) {
Node* tmp = new Node{ a->order, a->coeff + b->coeff, nullptr };
data (see GUIDATA)
% 获取输入框中的数字
num1 = str2double(get(handles.edit1, 'String'));
% 获取 cur->nxt = tmp;
cur = tmp;
}
a = a->nxt;
b = b->nxt第二个数字
num2 = 7;
% 计算结果
result = num1 + num2;
% 在结果区域;
}
else if (a->order > b->order) {
Node* tmp = new Node{ a->order, a显示结果
set(handles.text2, 'String', num2str(result));
% --- Executes on button press in pushbutton8.
function->coeff, nullptr };
cur->nxt = tmp;
cur = tmp;
a = a->nxt;
}
pushbutton8_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton8 (see GCBO)
% eventdata reserved - to else {
Node* tmp = new Node{ b->order, b->coeff, nullptr };
cur->nxt = tmp;
be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% 获取输入框中的 cur = tmp;
b = b->nxt;
}
}
while (a != nullptr) {
Node* tmp =数字
num1 = str2double(get(handles.edit1, 'String'));
% 获取第二个数字
num2 = 8;
new Node{ a->order, a->coeff, nullptr };
cur->nxt = tmp;
cur = tmp;
a =% 计算结果
result = num1 + num2;
% 在结果区域显示结果
set(handles.text2, 'String', a->nxt;
}
while (b != nullptr) {
Node* tmp = new Node{ b->order, b-> num2str(result));
% --- Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
%coeff, nullptr };
cur->nxt = tmp;
cur = tmp;
b = b->nxt;
}
return hObject handle to pushbutton9 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles head->nxt;
}
```
阅读全文