毕业论文论文范文课程设计实践报告法律论文英语论文教学论文医学论文农学论文艺术论文行政论文管理论文计算机安全
您现在的位置: 毕业论文 >> 课程设计 >> 正文

单链表的交并差

更新时间:2007-10-20:  来源:毕业论文

单链表的交并差-数据结构课程设计|数据结构课程设计#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#define null 0
#define M 100
/*定义链表*/
typedef int ElemType;
typedef struct Lnode
{
    ElemType data;
    struct Lnode *next;
};

/*返回链表长度*/
int lenth(struct Lnode **L)
{
    int n=0;
    struct Lnode *t;
    t=*L;
    while(t!=null)
        {
           n++;
           t=t->next;
        }
    return n;
}
/*返回指定节点的值*/
ElemType get(struct Lnode **L,int n)
{
      int i=1;
      struct Lnode *t;
      t=*L;
while (i<n&&t!=null)
  {
   t=t->next;
    i++;
  }
  if(t!=null)
    {
        return(t->data);
      }
  else
  {
        printf("The %dth Lnode haven't find !\n",n);
      }
}
/*定位指定值的节点的位置*/
int locate(struct Lnode **L,ElemType x )
{
      int n=1;
  struct Lnode *t;
      t=*L;
while (t!=null&&t->data!=x)
  {
   t=t->next;
    n++;
  }
  if(t==null)
  {
        return(0);
      }
  else
      {
    return(n);
      }
}
/*显示链表*/
void display(struct Lnode **L)
{
   struct Lnode *t;
    t=*L;
    if(t==null)
    {
        printf("The link is null!");
    }
    else
    {
do
          {
            printf("%d>>",t->data);
            t=t->next;
   }
while(t!=null);
    }
    printf("\n");
}

/*创建链表,并设置链表为空*/
void creat(struct Lnode **L)
{
    *L=null;
}
/*向链表中插入元素*/
void insert(struct Lnode **L,int n,ElemType x)
{
/*插在第n个节点的前面*/
    struct Lnode *t1,*t2;
    int j=1;
    t1=(struct Lnode *)malloc(sizeof(struct Lnode));
    t1->data=x;
    t2=*L;
    if(n==1)
    {
       t1->next=t2;
       *L=t1;
    }
    else
    {
        while(j<n-1&&t2->next!=null)
            {
               t2=t2->next;
               j++;
            }
        if(j==n-1)
            {
                t1->next=t2->next;
                t2->next=t1;
            }
        else
            {
                printf("Insert error!");
            }
    }
}
/*删除指定位置的节点*/
void delete(struct Lnode **L,int n)
{
      int i=1;
  struct Lnode *t1,*t2;
      t1=*L;
  if(n==1)
   {
    t2=t1;
    *L=t1->next;
   }
  else
   {
    while(i<n-1&&t1->next!=null)
     {
      t1=t1->next;
       i++;
     }
      if(t1->next!=null&&i==n-1)
       {
        t2=t1->next;
        t1->next=t2->next;
       }
      else
      {
               printf("Delete error!\n");
            }
   }
    if(t2==null)
{
     free(t2);
      }
}
/*初始化链表*/
void init(struct Lnode **L,int len)
{
    int d[M],i,j,k,ti;
    struct Lnode *t;
input:
    for(i=1;i<=len;i++)
    {
     scanf("%d",&d[i]);
    }
    for(j=1;j<=len;j++)
      for(k=j+1;k<=len;k++)
        {
         if(d[j]>d[k])
            {
              ti=d[j];
              d[j]=d[k];
              d[k]=ti;
            }
        }

[1] [2] [3] 下一页

单链表的交并差下载如图片无法显示或论文不完整,请联系qq752018766
设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©youerw.com 优文论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。