zoukankan      html  css  js  c++  java
  • 线性表重点

    第i个数据元素的存储位置是:LOC(ai)=LOC(a1)+(i-1)*m

    线性表的表长表示为(*L).len或者L->len。第i个元素写为L->v[i-1]

    单链表的头指针指向头结点称其为带头结点的单链接。若无特别说明,用的都是带头结点的单链表。

    p->data表示p指向的结点的数据域。

    p->next表示p指向的结点的指针域。

    p=(Lnode *)malloc(sizeof(Lnode);

    free(p)释放p所指向的结点空间。

    单链表的相关操作

    #include<stdio.h>
    #include<stdlib.h>
    typedef char elmentype;
    typedef struct node
    {
    	elementype data;
    	struct node *next;
    }Lnode,*linklist;//Lnode结点类型,linklist是指向结点的指针类型 
    
    void main()
    {
    	Lnode *h;
    	Lnode *creat();
    	h = creat();
    }
    Lnode *creat()//头插法 
    {
    	elementype ch;
    	h=(Lnode *)malloc(sizeof(Lnode));//建立头结点 
    	h->next=NULL;//使头结点的指针域为空 
    	while((ch=getchar(!)='
    '))
    	{
    		p=(Lnode *)malloc(sizeof(Lnode));//建立新结点p 
    		p->data=ch;//ch赋给p的数据域 
    		p->next=h->next;//改变指针状况 
    		h->next=p;//h的直接后继是p 
    	}
    	return h;
    }
    Lnode *creat()//尾插法 
    {
    	Lnode *h,*p,*t;
    	elementype ch;
    	h = (Lnode *)malloc(sizeof(Lnode));
    	h->next=NULL;
    	t=h;
    	while((ch=getchar()!='
    '));
    	{
    		p=(Lnode *)malloc(sizeof(Lnode));
    		p->data=ch;
    		p->next=NULL;
    		t->next=p;//t指向最后一个元素 
    		t=p;
    	}	
    	return h;
    }
    int lenth(Lnode *h)
    {
    	Lnode *p;
    	int i = 0;
    	p = h->next;//p访问第一个结点
    	while(p)
    	{
    		i++;
    		p=p->next;	
    	} 
    	return i;
    }
    
    void insert(Lnode *p,elementype x)//值为x的结点插在p后
    {
    	Lnode *s;
    	s = (Lnode *)malloc(sizeof(Lnode));//生成结点s 
    	s->data = x;	
    	s->next = p->next;
    	p->next = s;
    } 
    int insert(Lnode *h,int i,elementype x)//第i个元素中插入一个元素 
    {
    	Lnode *p,*s;
    	int j=0;
    	p=h;
    	while(p&&(j<i-1))//找第i-1个结点 
    	{
    		p=p->next;
    		j++;
    	}
    	if(p)
    	{
    		s = (Lnode *)malloc(sizoef(Lnode));
    		s->data=x;
    		s->next=p->next;
    		p->next=s;
    		return 1;
    	}
    	else 
    		return 0;
    }
    void dele(Lnode *p)
    {
    	Lnode *p;
    	if(p->next!=NULL)
    	{
    		q=p->next;//q是p的后继 
    		p->next=q->next;//删除q 
    		free(q);
    	}
    }
    

      

  • 相关阅读:
    JMeter 关联
    JMeter MD5加密
    JMeter 时间函数
    JMeter 常用设置
    JMeter 服务器资源监控
    js制作列表滚动(有滚动条)
    js监听事件
    获取窗口大小 并自适应大小变化
    js 标签云
    js 显示数字不断增加
  • 原文地址:https://www.cnblogs.com/claudia529/p/11103373.html
Copyright © 2011-2022 走看看