java用什么代替goto_java中可以使用goto语句,但不推荐使用。()

阅读以下应用说明、图和C++程序,将C++程序中(1)~(6)空缺处的语句填写完整。【说明】以下【C++程序】用于实现两个多项式的乘积运算。多项式的每一项由类Item描述,而多项式由类List描述。类List的成员函数主要有:createList():创建按指数降序链接的多项式链表,以表示多项式:reverseList():将多项式链表的表元链接顺序颠倒:multiplyList(ListL1,ListL2)计算多项式L1和多项式L2的乘积多项式。【C++程序】include <iostream.h>class List;class Item {friend class List;private:double quot ;int exp ;Item *next;Public:Item(double_quot,int_exp){ (1) ;}};class List{private:Item *list;Public:List(){list=NULL:}void reverseList();void multiplyList(List L1,List L2);void createList();};void List::createList(){ Item *p,*U,*pre;int exp;double quot;list = NULL;while (1) {cout << '输入多项式中的一项(系数、指数) :' << endl;cin >> quot >> exp:if ( exp<0 )break ; //指数小于零,结束输入if ( quot=0 )continue;p = list;while ( (2) ) { //查找插入点pre = p;p = p->next;}if ( p != NULL && exp = p->exp ) {p->quot += quot;continue ;}u =(3);if (p == list)list = u;elsepre->next = u;u ->next = p;}}void List::reverseList(){ Item *p, *u;if ( list==NULL )return;p = list ->next;list -> next = NULL;while ( p != NULL) {u = p -> next;p ->next = list;list = p;p = u;}}void List::multiplyList ( List L1, List L2 ){ Item *pL1,*pL2,*u;int k, maxExp;double quot;maxExp =(4):L2.reverseList();list=NULL;for ( k = maxExp;k >= 0;k-- ){pL1 = L1.list;while ( pL1 != NULL && pL1 -> exp > k )pL1 = pL1 ->next;pL2 = L2.1ist;while (pL2 NULL &&(5))pL2 = pL2 -> next;quot = 0.0;while (pL1 != NULL && pL2 != NULL){if(pL1->exp+pL2->exp==k) {(6)pL1 = pL1 -> next;pL2 = pL2 -> next;} else if ( pL1 -> exp + pL2 -> exp > k )pL1 = pL1 -> next;elsepL2 = pL2 -> next;}if ( quot !=0.0 ) {u = new item( quot, k );u -> next = list;list = u;}}reverseList ();L2. reverseList ():}void main(){ List L1,L2,L;

题型:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值