当前位置: 首页 > news >正文

中国建设银行e路通网站厦门软件开发工资一般多少

中国建设银行e路通网站,厦门软件开发工资一般多少,装饰公司网站制作,专业的营销型网站培训中心第一个是测试用例代码&#xff0c;测试的是两个带头的逆序链表相加&#xff0c;并且有反转操作 但是题目要求的是不带头链表直接相加&#xff0c;不需要逆转&#xff0c;输出结果也是逆序的&#xff0c; 题解放在第二个代码中 #include<stdio.h> #include<stdlib.h…

第一个是测试用例代码,测试的是两个带头的逆序链表相加,并且有反转操作

但是题目要求的是不带头链表直接相加,不需要逆转,输出结果也是逆序的,

题解放在第二个代码中

#include<stdio.h>
#include<stdlib.h>
typedef struct ListNode {int val;struct ListNode* next;
}List;List* reverse(List* L) {List* p = L;List* q = NULL;while (p != NULL) {List* temp = p->next;p->next = q;q = p;p = temp;}List* head = (List*)(malloc)(sizeof(List));head->next = q;List* temp = head;while (temp->next->next != NULL) {temp = temp->next;}temp->next = NULL;return head;
}
struct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2) {List*L1=reverse(l1);L1->val = 0;List*L2=reverse(l2);L2->val = 0;List* L3 = (List*)(malloc)(sizeof(List));L3->next = NULL;L3->val = 0;int flag = 0;while (L1 != NULL || L2 != NULL) {List* temp = (List*)(malloc)(sizeof(List));temp->next = NULL;temp->val = 0;if (L1) {temp->val += L1->val;L1 = L1->next;}if (L2) {temp->val += L2->val;L2 = L2->next;}if (flag == 1) {temp->val += 1;flag = 0;}//进位if (temp->val >= 10) {temp->val= temp->val % 10;flag = 1;}//大于10进位List* cur = L3;while (cur->next != NULL) {cur = cur->next;}cur->next = temp;if (L1 == NULL && L2 == NULL && flag == 1) {List* digital = (List*)(malloc)(sizeof(List));digital->val = 1;digital->next = NULL;temp->next = digital;}}L3->next->val = 0;return reverse(L3->next);
}
List* makeList() {List* L = (List*)(malloc)(sizeof(List));L->next = NULL;int num;while (1) {scanf("%d", &num);if (num == 0) {break;}List* temp = (List*)(malloc)(sizeof(List));temp->next = NULL;temp->val = num;List* p = L;while (p->next != NULL) {p = p->next;}p->next = temp;}return L;
}
void print_List(List* L) {L = L->next; // 跳过头节点while (L != NULL) {printf("%d ", L->val);L = L->next;}printf("\n");
}int main() {List* L1 = makeList();printf("打印L1\n");print_List(L1);List* L3=reverse(L1);List* L2= makeList();printf("打印L2\n");print_List(L2);List* L4 = reverse(L2);printf("打印L3\n");print_List(L3);printf("打印L4\n");print_List(L4);List* L5 = addTwoNumbers(L3, L4);printf("打印L5\n");print_List(L5);
}

struct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2) {struct ListNode* L3 = (struct ListNode*)(malloc)(sizeof(struct ListNode));L3->next = NULL;L3->val=0;int flag = 0;while (l1 != NULL || l2 != NULL) {struct ListNode* temp = (struct ListNode*)(malloc)(sizeof(struct ListNode));temp->next = NULL;temp->val = 0;if (l1) {temp->val += l1->val;l1 = l1->next;}if (l2) {temp->val += l2->val;l2 = l2->next;}if (flag == 1) {temp->val += 1;flag = 0;}//进位if (temp->val >= 10) {temp->val= temp->val % 10;flag = 1;}//大于10进位struct ListNode* cur = L3;while (cur->next != NULL) {cur = cur->next;}cur->next = temp;if (l1 == NULL && l2 == NULL && flag == 1) {struct ListNode* digital = (struct ListNode*)(malloc)(sizeof(struct ListNode));digital->val = 1;digital->next = NULL;temp->next = digital;}}return (L3->next);
}

http://www.yayakq.cn/news/543890/

相关文章:

  • 网站规划的步python抓取更新wordpress
  • 网站如何做移动适配3有免费建网站
  • 优化网站的目的wordpress 插件 朋友圈
  • 查建设标准网站邹平建设网站
  • 网站建设咨询什么广东黄页企业名录
  • 农业门户网站模板企业官网怎么编辑
  • 专业建设网站公司网站建设百度云资源
  • 锦州网站建设信息激光东莞网站建设
  • 提示网站正在建设中网站改版竞品分析怎么做
  • 宁波建站方案h5网站架设
  • 云南省建设厅网站发文网站标签页在哪里设置
  • 商城模板建站价格手机建网站 教程
  • 设计开发建设网站找建筑工程平台
  • 遂宁网站开发兴安网站建设
  • 企业网站推广定义开发商城网站多少钱
  • 洛阳建设厅网站企业网站策划方案网站建设方案
  • 什么是网站托管泉州市新濠网络科技有限公司
  • 无锡网站建设外包优势wordpress cdn sae jquery
  • 龙口城乡建设局官方网站网站建设服务费下什么科目
  • 淄川区建设局网站北京海淀区的科技有限公司
  • 可以自己设计一个公司的网站小程序代理加盟政策
  • 东莞家具行业营销型网站建设多少钱网站建设培训总结
  • 企业用什么做网站计算机专业都学什么
  • 网站谷歌地图提交支付宝也做网站吗
  • 如何做招聘网站运营网站运营专员做什么
  • 花都区pc端网站建设微网站 杭州
  • 自己怎么做搬家网站成都网站建设是什么
  • 株洲网站排名开发软件app公司
  • phpstudy做网站运营的坏处wordpress手机主题开发
  • 网站安全狗 拦截301不上此网站枉做男人