数据结构上机测试2-1:单链表操作A
2014-11-04 20:39
253 查看
传送门
代码:#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, m; struct node *head, *tail, *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; } scanf("%d", &m); printf("%d\n", n); tail = head->next; while(tail!=NULL) { if(tail->next==NULL) printf("%d\n", tail->data); else printf("%d ", tail->data); tail= tail->next; } p = head; q = head->next; while(q!=NULL) { if(q->data==m) { p->next = q->next; free(q); cnt++; } else p = p->next; q = p->next; } printf("%d\n", n-cnt); tail = head->next; while(tail!=NULL) { if(tail->next==NULL) printf("%d\n", tail->data); else printf("%d ", tail->data); tail = tail->next; } } return 0; }
相关文章推荐
- 数据结构上机测试2-2:单链表操作B
- 数据结构上机测试2-2:单链表操作B
- 数据结构上机测试2-2:单链表操作B
- 数据结构上机测试2-1:单链表操作A
- 数据结构上机测试2-1:单链表操作A
- 1138 数据结构上机测试2-1:单链表操作A
- 数据结构上机测试2-1:单链表操作A
- 数据结构上机测试2-1:单链表操作A
- 数据结构上机测试2-2:单链表操作B
- 寒假第二天--线性表--数据结构上机测试2-2:单链表操作B
- 【1138】数据结构上机测试2-1:单链表操作A(顺序建表+删除节点)(SDUT)
- 数据结构上机测试2-2:单链表操作B
- 1139-数据结构上机测试2-2:单链表操作B
- 数据结构上机测试2-1:单链表操作A
- 【1139】数据结构上机测试2-2:单链表操作B (逆序建表+重复元素删除)
- 【1139】数据结构上机测试2-2:单链表操作B
- 暑假集训第1天链表-数据结构上机测试2-1:单链表操作A
- 数据结构上机测试2-1:单链表操作A
- 数据结构上机测试2-2:单链表操作B
- 【1139】数据结构上机测试2-2:单链表操作B (逆序建表+重复元素删除)