#include<stdio.h>
#include<iostream.h>
#include<malloc.h>
#include<stdlib.h>
#include<string.h>
#define null 0
#define M 100
struct Lnode
{
char data;
struct Lnode *next;
};
int lenth(struct Lnode **L)
{
int n=0;
struct Lnode *t;
t=*L;
while(t!=null)
{
n++;
t=t->next;
}
return n;
}
void creat(struct Lnode**L)
{
*L=null;
}
//从功能化分上,这个函数不需要知道现在插入第几个字符
//困为你init函数中是先对一个串的字符进行了排序,所以
//这里直接插入链表的尾部就行了
void insert(struct Lnode**L, char d)
{
struct Lnode *t1,*t2;
int j=1;
t1=(struct Lnode*)malloc(sizeof(struct Lnode));
t1->data=d;
t1->next=NULL;
if(*L==NULL)
{
*L=t1;
return;
}
t2=*L;
while(t2->next!=NULL)
{
t2=t2->next;
}
t2->next=t1;
}
/*显示链表*/
void display(struct Lnode **L)
{
struct Lnode *t;
t=*L;
if(t==null)
{
cout<<"The link is null!";
}
else
{
for(;t!=null;)
{
cout<<t->data;
t=t->next;
}
}
cout<<"\n";
}
/* 初始化和排序*/
void init(struct Lnode**L,int n,char str[])
{
int i,j,k,x=0,p=0;
char ti,d[100];
for(i=0;i<=n-1;i++)
{
d[i]=str[i];
}
for(j=0;j<n-1;j++)
for(k=j+1;k<=n-1;k++)
{
if(int(d[j])>int(d[k]))
{
ti=d[j];
d[j]=d[k];
d[k]=ti;
}
}
creat(&*L);
if(n>0)
insert(&*L,d[0]);//第一个字符是要插入的
for(int h=1;h<n;h++)
{
if(d[h] != d[h-1])
insert(&*L,d[h]);
}
}
/*删除指定位置的节点*/
void delet(struct Lnode **L,int n)
{
int i=1;
struct Lnode *t1,*t2;
t1=*L;
if(n==1)
{
t2=t1;
*L=t1->next;
}
else
{
while(i<n-1&&t1->next!=null)
{
t1=t1->next;
i++;
}
if(t1->next!=null&&i==n-1)
{
t2=t1->next;
t1->next=t2->next;
}
else
{
cout<<"Delete error!\n";
}
}
if(t2==null)
{
free(t2);
}
}
/*返回指定节点的值*/
char get(struct Lnode **L,int n)
{
int i=1;
struct Lnode *t;
t=*L;
while (i<n&&t!=null)
{
t=t->next;
i++;
}
if(t!=null)
{
return(t->data);
}
else
{
cout<<"The Lnode haven't find !\n";
}
return(t->data);
}
void copy(struct Lnode **L1,struct Lnode **L2 )
{
struct Lnode *t=*L1;
creat(&*L2);
while(t != NULL)
{
insert(&*L2,t->data);
t=t->next;
}
}
/*求交集*/
void intersection(struct Lnode **L1,struct Lnode **L2,struct Lnode **L3)
{
struct Lnode *t1,*t2;
t1=*L1;
t2=*L2;
creat(&*L3);
while(t1 != NULL && t2 != NULL)
{
if(t1->data==t2->data )
{
insert(&*L3,t1->data);
t1=t1->next;
t2=t2->next;
}
else if(t1->data<t2->data)
{
t1=t1->next;
}
else
{
t2=t2->next;
}
}
}
/*求并集*/
void unionset(struct Lnode **L1,struct Lnode **L2,struct Lnode **L3)
{
struct Lnode *t1,*t2;
creat(&*L3);
t1=*L1;
t2=*L2;
while(t1 != NULL && t2 != NULL)
{
if( t1->data==t2->data )
{
insert(&*L3,t1->data);
t1=t1->next;
t2=t2->next;
}
else if( t1->data<t2->data)
{
insert(&*L3,t1->data);
t1=t1->next;
}
else
{
insert(&*L3,t2->data);
t2=t2->next;
}
}
if(t1==NULL)
{
while(t2!=NULL)
{
insert(&*L3,t2->data);
t2=t2->next;
}
}
else
{
while(t1!=NULL)
{
insert(&*L3,t1->data);
t1=t1->next;
}
}
}
/*求差集*/
void diffrenceset(struct Lnode **L1,struct Lnode **L2,struct Lnode **L3)
{
struct Lnode *t1=*L1;
struct Lnode *t2=*L2;
creat(&*L3);
while(t1 != NULL )
{
if(t2==NULL || t1->data<t2->data )
{
insert(&*L3,t1->data);
t1=t1->next;
}
else if(t1->data>t2->data)
{
t2=t2->next;
}
else
{
t1=t1->next;
t2=t2->next;
}
}
}
void main()
{
int len1=0,len2=0;
char r1[100],r2[100];
cin>>r1;
int
评论10