长整数的运算_算法与数据结构课程设计(编辑修改稿)内容摘要:

(h1next!=0) { p1priordata=1。 p1data+=10000。 } } p1=p1prior。 } if(h1nextdata=10000) //处理最前面的数 6 { InsertNode(h1,0,h1nextdata/10000)。 h1nextnextdata%=10000。 } if(h1data=10000) { InsertNode(h1,0,h1nextdata/10000)。 h1nextnextdata%=10000。 } PrintNode(h1)。 } 3. 函数的调用关系图 开始 主函数 调运 void add(DLNode *h1,DLNode *h2) 建立链表 主函数 结束束 ]) 调运 void InitNode(DLNode *h1) 建立运算 7 4. 调试分析 a、 调试中遇到的问题及对问题的解决方法 调试过程中的困难: 在数据的运算中,应为是根据数的大小来选择运算的,所以过程相对比较繁琐。 而且对于双向链表的两个指针的定位以及链表的插入和删除等操作花费的较多的时间。 在这查阅参照了大量的网络资料。 b、算法的时间复杂度和空间复杂度 由于链表采用双向循环链表结构,可以从链表两头操作,各种操作的算法时间复杂度比较合理,各函数以及确定链表中的结点位置都是 O( n) ,n 为链表长度。 5. 测试结果 a、 输入 0和 0做加法运算,输出“ 0”,结果如下图: b、 输入 2345, 6789 和 7654, 3211 做减法运算,输出“ 1, 0000, 0000”,结果如下图: c、 输入 1, 0000, 0000, 0000 和 9999, 9999 做减法运算,输出“ 9999, 0000,0001”,结果如下图: 8 d、 输入 1, 0001, 0001 和 1, 0001, 0001 做减法运算,输出“ 0”,结果如 下图: e、 输入 1,2345,6789 和 9,8765,4321 做加 法运算, 结果如下图: 6. 源程序(带注释) include include include include define N 100 typedef int DataType。 typedef struct DoubleNode //定义链表元素 9 { DataType data。 struct DoubleNode *prior。 struct DoubleNode *next。 }DLNode。 void InitNode(DLNode **head) //初始化链表 { if((*head=(DLNode*)malloc(sizeof(DLNode)))==NULL) exit(1)。 (*head)prior=*head。 (*head)next=*head。 } int InsertNode(DLNode *head,int n,DataType x) //向链表第 N 个位置插入元素 X { DLNode *p,*nt。 int i=0。 p=headnext。 while(p!=headamp。 amp。 in) { p=pnext。 i++。 } if(i!=n) { printf(插入位置错误 \n)。 return 0。 } if((nt=(DLNode *)malloc(sizeof(DLNode)))==NULL) exit(1)。 ntdata=x。 ntprior=pprior。 ntpriornext=nt。 ntnext=p。 pprior=nt。 10 return 1。 } int digit(int n) //判断整数 N 有几位 { int i。 for(i=1。 n/=10,i++) { if(n/10==0) return i。 } } void PrintNode(DLNode *head) //打印链表 { DLNode *p=headnext。 int i。 while(pdata==0) //去掉前面的一串 0 { p=pnext。 if(p==head) { printf(0 \n)。 return。 } }。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。