数据结构实验之链表五:单链表的拆分
来源:互联网 发布:淘宝哪家手机店靠谱 编辑:程序博客网 时间:2024/04/29 22:37
~ ~ ~ ~ ~ ~ ~ ~ 题目
代码:
#include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>using namespace std;struct node{int data;struct node *next;};int main(){ int n, i, cnt; struct node *head, *head2, *tail, *tail2, *p, *q; head = (struct node *)malloc(sizeof(struct node)); head->next = NULL; tail = head; while(~scanf("%d", &n)){cnt = 0;for(i=0; i<n; i++){p = new node; p->next = NULL; scanf("%d", &p->data); tail->next = p; tail = p;}head2 = new node;head2->next = NULL;tail2 = head2;q = head;p = q->next;while(p!=NULL){if(p->data%2==0){tail2->next = p;tail2 = p;q->next = p->next;tail2->next = NULL;p = q->next;cnt++;}else {q = q->next;p = q->next;}}printf("%d %d\n", cnt, n-cnt);head2 = head2->next;while(head2!=NULL){if(head2->next==NULL)printf("%d\n", head2->data);else printf("%d ", head2->data);head2 = head2->next;}head = head->next;while(head!=NULL){if(head->next==NULL)printf("%d\n", head->data);else printf("%d ", head->data);head = head->next;}}return 0;}
0 0
- 数据结构实验之链表五:单链表的拆分
- 数据结构实验之链表五:单链表的拆分
- 数据结构实验之链表五:单链表的拆分
- 数据结构实验之链表五:单链表的拆分
- 数据结构实验之链表五:单链表的拆分
- 数据结构实验之链表五:单链表的拆分
- 数据结构实验之链表五:单链表的拆分
- 数据结构实验之链表五:单链表的拆分
- 数据结构实验之链表五:单链表的拆分
- 数据结构实验之链表五:单链表的拆分
- 数据结构实验之链表五:单链表的拆分
- 数据结构实验之链表五:单链表的拆分
- 数据结构实验之链表五:单链表的拆分
- 数据结构实验之链表五:单链表的拆分
- 数据结构实验之链表五:单链表的拆分
- 数据结构实验之链表五:单链表的拆分
- 数据结构实验之链表五:单链表的拆分
- 数据结构实验之链表五:单链表的拆分
- 怎么安装mysql(图解)
- openjdk下载
- WEB应用中的SESSION知多少
- 关于EJB,查看资料,整理的笔记
- ubuntu配置
- 数据结构实验之链表五:单链表的拆分
- 干货分享: 长达150页的openvswitch的ppt,不实验无真相
- [bzoj2301: [HAOI2011]Problem b] 求
- POSIX互斥锁
- eclipse 下github 安装
- MAC - 当在brew中找不到想要的PHP扩展时的解决办法
- C语言实现读写配置文件项目
- Layer基本操作
- android 开发 ------- 接口文档 规范