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

📄 indert.c

📁 c++写得对于链表结构体操作的函数 实现了链表的基本操作
💻 C
字号:
#include<stdio.h>#include<stdlib.h>#define LEN sizeof (struct stu)typedef struct stu{	int num;	int age;	struct stu *next;}TYPE;TYPE *insert1(int n){	struct stu *head,*pf,*pb;	int i;	for (i=0;i<n;i++)		{		pb=(TYPE*)malloc(LEN);		printf("input Number and Age\n");		scanf("%d%d",&pb->num,&pb->age);		if(i==0)		pf=head=pb;		else pf->next=pb;		pb->next=NULL;		pf=pb;		}		return(head);}TYPE *insert(TYPE *pi,TYPE *pj){	TYPE *pf,*pb,*ps,*p;	pb=pi;	ps=pj;	while(ps!=NULL)	{		while(ps->num>pb->num&&(pb->next!=NULL))		{			pf=pb;			pb=pb->next;		}		if(ps->num<=pb->num)		{			if(pi==pb)				pi=ps;			else				pf->next=ps;			p=ps->next;			ps->next=pb;			}		else			{                         pb->next=ps;                         p=ps->next;                         ps->next=NULL;			             //ps->next=NULL;            }        ps=p;		}		return (pi);	}void delete_stu(TYPE *head){     TYPE *p=head;     TYPE *q;     while(p!=NULL)     {                   q=p->next;                   free(p);                   p=q;     }}int main(){	TYPE *p,*q,*s;	int n,m;	scanf("%d%d",&n,&m);	p=insert1(n);	q=insert1(m);	s=insert(p,q);	while(s!=NULL)	{	printf("%d\t%d\n",s->num,s->age);	s=s->next;	}	delete_stu(p);	delete_stu(q);	getchar();	getchar();	return 0;		}                                                                                                              

⌨️ 快捷键说明

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