Project

Profile

Help

HostedRedmine.com has moved to the Planio platform. All logins and passwords remained the same. All users will be able to login and use Redmine just as before. Read more...

Task #555138 » 15.txt

俊延 凃, 2016-05-19 01:15 AM

 
#include<stdio.h>
#define LEN sizeof(struct number)
struct number /*?????ź?????*/
int name;
int num;
struct number * next;
};

struct number * create() /*????????????*/
{
struct number * head,* new,* tail,* p;
int count=0;
while(1)
{
new=(struct number *)malloc(LEN);
printf("input Name and Number\n");
scanf("%d %d",&new->name,new->num); /*?û??????ź?????*/
if(new->name==0)
{
free(new);
break;
}
else if(count==0)
{
head=new;
tail=new;
}
else
{
tail->next=new;
tail=new;
}
count++;
}
tail->next=NULL;
return(head);
}

struct number * delist(struct number *head,int name) /*ɾ?????ֵĺ???*/
{
struct number * p0,* p1;
p1=head;
if(head==NULL)
{
printf("\nempty list!\n");
}
else
if(p1->name==name) /*?ҵ???ͬ???*/
head=p1->next;
else
{
while(p1->name!=name&&p1->next!=NULL) /*??һ?Ų?*/
{
p0=p1;
p1=p1->next;
}
if(p1->name==name)
{
p0->next=p1->next;
printf("The node is deleted\n");
}
else
printf("The node can not been foud!\n");
}
return head;
}

struct number * insert(struct number * head,struct number * new)
{ /*???뺯??*/
struct number * p0,* p1;
p1= head;
if(head==NULL)
{
head=new;
new->next=NULL;
}
else
if(new->name<p1->name) /*Ѱ?????????ʺϵ?λ?ò???*/
{
new->next=head;
head=new;
}
else
{
while(new->name>p1->name)
{
p0=p1;
p1=p1->next;
}
new->next=p0->next;
p0->next=new;
}
return(head);
}

void print(struct number * head) /*??ӡ????*/
{
struct number * p;
p=head;
if(head==NULL) /*??ʵ?ò???*/
printf("list is empty\n");
else
while(p!=NULL)
{
printf("%d%d\n",p->name,p->num); /*??ӡ????????*/
p=p->next;
}
}

struct number * find(struct number * head,struct number * new)
{ /*??ѯ????*/
struct number * p0,* p1;
p1= head;
if(head==NULL)
{
head=new;
new->next=NULL;
}
else
if(new->name!=p1->name) /*Ѱ?Һ?????????ͬ?Ľڵ?,?????????¶?*/
{
new->next=head;
head=new;
}
else
{
while(new->name==p1->name)
{
printf????find successfully!\n????;
printf(??%d %d??,p1->name,p1->num);
}
}
return(head);
}

void main() /*??????*/
{
struct number * head,* p;
int name;
head=create(); /*??????һ???ú???*/
print(head);
printf("Input the delete number:");
scanf("%d",&name);
head=delist(head,name);
print(head);
printf("Input the inserted name and number:");
p=(struct number *)malloc(LEN);
scanf("&d&d",p->name,p->num);
head=insert(head,p);
print(head);
printf(??Input the found name:??);
scanf(??%d??,&name);
head=find(head,p);
print(head);
}
    (1-1/1)