链表实现集合的交并差
第一版
#include <iostream>
#include <string>
using namespace std;
struct LNode
{
char data;
struct LNode *next;
};
LNode* createList()
{
int n;
LNode* head = new LNode;
LNode* pre = head;
cout << "请输入字符串的字母个数" << endl;
cin >> n;
while(n<=0)
{
cout << "请输入一个大于零的数" << endl;
cin >> n;
}
cout << "请输入字符串" << endl;
for (int i = 0; i < n; i++)
{
LNode* p = new LNode;
cin >> p->data;
pre->next = p;
pre = p;
p->next = NULL;
}
return head;
}
void display(LNode* head)
{
LNode* p = head->next;
while(p != NULL)
{
cout << p->data;
p = p->next;
cout << " ";
}
cout << endl;
}
void sort(LNode* head)
{
LNode* cur = NULL;
LNode* tag = NULL;
cur = head;
while(cur != tag)
{
while(cur