ctve facetest 链表删除save other list
来源:互联网 发布:网络流行照片 编辑:程序博客网 时间:2024/06/06 18:20
#include <iostream>
using namespace std;
struct Node
{
char data;
Node* next;
};
Node* create()
{
Node* head = NULL;
Node* rear = head;
Node* p; // The pointer points to new created node.
char tmp;
do
{
cout << "Please input integer or char '#':";
cin >> tmp;
if (tmp != '#')
{
p = new Node;
p->data = tmp;
p->next = NULL;
if (head == NULL)
{
head = p;
}
else
{
rear->next = p;
}
rear = p;
}
} while (tmp != '#');
return head;
}
void print(Node* head)
{
Node* p = head;
if (head != NULL)
{
do
{
cout << p->data << ' ';
p = p->next;
} while (p != NULL);
}
cout << endl;
}
unsigned int del(Node* l1, Node* l2)
{
static int cnt = 0;
if (!l1 || !l2)
{
return NULL;
}
Node *p = new Node;
p->next = l1;
Node *pL1 = l1, *pL2 = l2, *head = p;
while (pL1 && pL2)
{
if (pL1->data < pL2->data)
{
pL1 = pL1->next;
p = p->next;
cnt++;
}
else if (pL1->data > pL2->data)
{
pL2 = pL2->next;
//cnt++;
}
else
{
pL1 = pL1->next;
p->next = pL1;
cnt++;
}
}
l1 = head->next;
return cnt;
}
int main()
{
cout << "Please input the first list:" << endl;
Node* l1 = create();
cout << endl << "Please input the second list:" << endl;
Node* l2 = create();
cout << endl << "--------------------------" << endl;
cout << "The first list is: ";
print(l1);
cout << "The second list is: ";
print(l2);
cout << del(l1, l2);
//cout << endl << "The result list is: ";
//print(l);
return 0;
}
这个程序是返回一个整数,该整数是列表中删除的另一表中的个数。
http://blog.csdn.net/troubleshooter/article/details/7716815
0 0
- ctve facetest 链表删除save other list
- facetest
- faceTest
- [other] 强力删除命令
- 树 facetest
- ZR facetest
- zx facetest
- DD facetest
- 循环链表list删除元素
- c、c++ facetest good
- 双向链表容器list的头尾中,全部删除
- STL双向链表之删除重复元素(list)
- STL链表之删除指定元素(list)
- Leetcode Remove Linked List Elements 删除链表中的元素
- [C++]Remove Linked List Elements 删除链表中的元素
- Remove Linked List Elements 删除链表中指定元素
- Remove Linked List Elements 链表元素的删除
- [lintcode]Remove Linked List Element 删除链表中的元素
- 【IOS开源项目】10个ios开发者必需要研究的swift开源项目
- 关于LeetCode中Palindrome Linked List一题的理解
- 一亿数据获取最大值的前100位
- 改变xcode代码区的背景颜色
- Android之禁止ViewPager滑动
- ctve facetest 链表删除save other list
- 堆排序
- 嵌入式学习--work5 RTC实时时钟学习
- CentOS安装vsftpd后不能新建文件夹的解决方法
- Java - 华为机试训练 - 明明的随机数
- fedora 24 编程时使用sqlite3出现<sqlite3.h>cont not find file or directory
- Java学习起始(标识符,关键字,常量及变量)
- EL表达式中的empty运算符和三元运算符
- Java笔记(1)- Java基础知识、类、对象、运算符、数据类型