该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
# include "iostream.h"
# include "string.h"
# include "malloc.h"
# include "stdlib.h"
# define N 10
# define NULL 0
# define LEN sizeof(struct LNode)
struct LNode
{
char name[10];
int count;
struct LNode *next;
};
struct LNode *creat(void)
{
int i,n=0;
struct LNode *head,*p1,*p2;
cout<
head=NULL;
for(i=0;i
{
p1=(struct LNode *)malloc(LEN);
cin>>p1->name;
p1->count=0;
n=n+1;
if(n==1)
head=p1;
else
p2->next=p1;
p2=p1;
}
p2->next=NULL;
return(head);
}
void count(struct LNode *head)
{
struct LNode *p1=head,*p2=head;
while(p1!=NULL)
{
while(p2!=NULL)
{
if(strcmp(p1->name,p2->name)==0)
{
p1->count++;
}
p2=p2->next;
}
cout<name<count<
p2=head;
p1=p1->next;
}
}
struct LNode *sort(struct LNode *head,char *a)
{
struct LNode *p,*q;
int t;
for(p=head;p!=NULL;p=p->next)
{
for(q=p->next;q!=NULL;q=q->next)
{
if(p->countcount)
{
t=q->count;
strcpy(a,q->name);
q->count=p->count;
strcpy(q->name,p->name);
p->count=t;
strcpy(p->name,a);
}
}
}
return head;
}
struct LNode *del(struct LNode *head)
{
struct LNode *p1=head,*p2,*p3;
p2=p1->next;
p3=p1;
if(head!=NULL)
{
while(p1!=NULL)
{
p2=p1->next;
while(p2!=NULL)
{
if(strcmp(p2->name,p1->name)==0)
{
p3->next=p2->next;
p2=p2->next;
}
else
{
p3=p2;
p2=p2->next;
}
}
p1=p1->next;
p3=p1;
}
}
else
cout<
return head;
}
void print(struct LNode *head)
{
struct LNode *p;
cout<
p=head;
if(head==NULL)
cout<
else
{
while(p!=NULL)
{
cout<name<count<
p=p->next;
}
}
cout<
}
void main()
{
char a[10]=" ",*p=a;
struct LNode *head;
head=creat();
cout<
cout<
count(head);