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

📄 lib.h

📁 数据结构实验报告等综合内容
💻 H
字号:
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define N 5
#define NULL 0
#define LEN sizeof (struct nodetype)
  struct nodetype
    {
      int data;
      struct nodetype *next;
    };
  void red(int a[N])
    {
      int i;
      for(i=1;i<=N;i++)
       {
	scanf("%d",&a[i]);
       }
    }
  void writ(struct nodetype *la)
  {
     struct nodetype *p;
     p=la;
     while(p->next!=NULL)
     {
       printf("%d ",p->next->data);
       p=p->next;
     }
  }
  struct nodetype crt_linklist(struct nodetype *la,int a[N])
  {
    struct nodetype *p;
    int i;
    la=(struct nodetype *) malloc (LEN);
    la->next=NULL;
    for(i=N;i>=1;i--)
    {
      p=(struct nodetype *) malloc (LEN);
      p->data=a[i];
      p->next=la->next;
      la->next=p;
    }
    return(*la);
   }
   int get_linklist(struct nodetype *la,int i)
   {
     struct nodetype *p;
     int j,z;
     p=la->next;
     j=1;
     while((p!=NULL)&&(j<i))
     {
       p=p->next;
       j=j+1;
     }
     if((p!=NULL)&&(j==i))
       z=p->data;
       z=0;
     return(z);
  }
  void ins_linklist(struct nodetype *la,int i,int b)
  {
    struct nodetype *p,*s;
    int j;
    p=la;
    j=0;
    while((p!=NULL)&&(j<i-1))
    {
      p=p->next;
      j=j+1;
    }
    if((p==NULL)|(j>i-1))
       printf("No this position\n");
       else
      {
	s=(struct nodetype *)malloc(LEN);
	s->data=b;
	s->next=p->next;
	p->next=s;
      }
  }
  void del_linklist(struct nodetype *la,int i)
  {
    struct nodetype *p,*q;
    int j;
    p=la;
    j=0;
    while((p->next!=NULL)&&(j<i-1))
    {
      p=p->next;
      j=j+1;
    }
    if((p->next==NULL)|(j>i-1))
      printf("No this position\n");
      else
      {
	q=p->next;
	p->next=p->next->next;
	free(q);
      }
    }
   struct nodetype  merge_linklist(struct nodetype *la,struct nodetype *lb)
    {
      struct nodetype *pa,*pb,*pc,*lc;
      pa=la->next;
      pb=lb->next;
      lc=la;
      pc=lc;
      while((pa!=NULL)&&(pb!=NULL))
      {
	if (pa->data<=pb->data)
	{
	  pc->next=pa;
	  pc=pa;
	  pa=pa->next;
	}
	else
	{
	  pc->next=pb;
	  pc=pb;
	  pb=pb->next;
	}
      }
	if(pa!=NULL)
	pc->next=pa;
	else
	pc->next=pb;
      //	free(lb);
	return(*lc);
    }

⌨️ 快捷键说明

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