⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fgdf.txt

📁 里面包括: 哈夫曼编码
💻 TXT
字号:
#include<malloc.h>
#include <stdio.h> 
#include<string.h>
#include<iostream.h>
#define NULL 0
#define LEN sizeof(struct student)
struct student
{long phone;
 char num[20];
 char name[20];
 struct student *next;
};

int n;
struct student *creat(void)
{struct student *head;
 struct student *p1,*p2;
 n=0;
 p1=p2=(struct student *)malloc(LEN);
 gets(p1->num);
 gets(p1->name);
 cin>>p1->phone;
 head=NULL;
 while(strcmp(p1->num,"over"))
 {n=n+1;
  if(n==1)head=p1;
  else p2->next=p1;
  p2=p1;
  p1=(struct student*)malloc(LEN);
  gets(p1->num);
  gets(p1->name);
  cin>>p1->phone;;
 }
 p2->next=NULL;
 return(head);
}

////

void print(struct student *head)
{
	struct student *p;
	cout<<endl<<"NOW,These "<<n<<" records are:"<<endl;
	p=head;
	if(head!=NULL)
		do
		{ cout<<p->num<<','<<p->name<<','<<p->phone<<endl;
		  p=p->next;
		}while(p!=NULL);
}

////

struct student *del(struct student *head,char num[20])
{
struct student *p1,*p2;
if (head==NULL)
 {cout<<"list null!"<<endl;
  goto end;
 }
p1=head;
while(strcmp(num,p1->num) && p1->next!=NULL)
{p2=p1;p1=p1->next;}
if (!strcmp(num,p1->num))
{if(p1==head)head=p1->next;
 else p2->next=p1->next;
 cout<<"delete:"<<num<<endl;
 n=n-1;
}
else cout<<num<<" not been found!"<<endl;
end: return(head);
}

//////

struct student *find(struct student *head,char num[20])
{
struct student *p1,*p2;
p1=head;
while(strcmp(num,p1->num) && p1->next!=NULL)
{p2=p1;p1=p1->next;}
if (!strcmp(num,p1->num))
{cout<<endl<<"find:"<<num<<endl;head=p1;
 cout<<head->num<<','<<head->name<<','<<head->phone<<endl;
}
else cout<<num<<"  not been found!"<<endl;
 return(head);
}


///////

struct student *insert(struct student *head,struct student *stud)
{
 struct student *p0,*p1,*p2;
 p1=head;
 p0=stud;
 if(head==NULL){head=p0;p0->next=NULL; }
 else   
 {while((strcmp(p0->num,p1->num))&&(p1->next!=NULL))
 {p2=p1;
  p1=p1->next;}
  if(!strcmp(p0->num,p1->num))
  {
	  if(head==p1)head=p0; 
      else p2->next=p0;
      p0->next=p1;
  }
  else  {p1->next=p0;p0->next=NULL;}
 }
 n=n+1;
 return(head);
}

//////////////////

void main()
{
  struct student *head,*stu;
  char del_num[20],need_num[20];
  cout<<"input records:"<<endl;
  head=creat();
  print(head);
  cout<<endl<<"input the deleted number"<<endl;
  gets(del_num);
  while(strcmp(del_num,"over"))
  {head=del(head,del_num);
   print(head);
   cout<<"input the deleted number:"<<endl;
   gets(del_num);
  }
  cout<<endl<<"input the insert number"<<endl;
  stu=(struct student *)malloc(LEN);
  gets(stu->num);
  gets(stu->name);
  cin>>stu->phone;;
  while(strcmp(stu->num,"over"))
  {head=insert(head,stu);
   print(head);
   cout<<endl<<"input the insert number"<<endl;
   stu=(struct student *)malloc(LEN);
   gets(stu->num);
   gets(stu->name);
   cin>>stu->phone;
  }

  cout<<endl<<"input the needed number"<<endl;
  gets(need_num);
  while(strcmp(need_num,"over"))
  {head=find(head,need_num);
   
   cout<<"input the needed number:"<<endl;
   gets(need_num);
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -