01-顺序表

1>>问:数据结构英文
-->>DS = data struct

2>>DS = (D,R)  
//D为数据元素的集合 -- R为D上关系的集合
D = {2I+1 | i = 0,1,2,3,4}
R = {<1,3> , <3,5> , <5,7> , <7,9> }

3>>问:逻辑结构
-->>集合(零散),线性,树状,图

4>>问:存储结构
-->>顺序存储 , 链式存储 , 索引存储 , 散列存储

5>>问:线性表
-->>多个相同数据元素的有限序列!
-->>直接前驱就是前一个元素
-->>直接后驱就是后一个元素

线性表之顺序表

1>>seqlist.h

#ifndef __SEQLIST_H__
#define __SEQLIST_H__
#include<stdbool.h>

#define MAXSIZE 100 
typedef struct NODE{
	int data[MAXSIZE];
	int sub;	
}seqlist_t;

seqlist_t* create_seqlist(void);
void show_seqlist(seqlist_t *L);
bool insert_seqlist(seqlist_t *L,int x,int pos);
bool delete_seqlist(seqlist_t *L,int pos);
bool change_seqlist(seqlist_t *L,int x,int pos);
int search_seqlist(seqlist_t *L,int x);

#endif

2>>seqlist.c

sequential有序的
#include <stdio.h>
#include <stdlib.h>
#include "seqlist.h"
#include <stdbool.h>
seqlist_t* create_seqlist()
{
	seqlist_t *L = NULL;
	L = (seqlist_t*)malloc(sizeof(seqlist_t));
	L->sub = -1;
	return L;
} 


void clear_seqlist(seqlist_t *L)
{
	free(L);
}

void show_seqlist(seqlist_t *L)
{
	int i=0;
	for(i;i<=L->sub;i++)
	{
		printf("%d\t",L->data[i]);
	}
}
bool insert_seqlist(seqlist_t *L,int x,int pos)
{
	int i = L->sub;
	for(i;i>pos;i--) //记得后移
	{
		L->data[i] = L->data[i-1];
	}
	L->sub+=1;
	L->data[pos] = x;
	return true;
}

bool delete_seqlist(seqlist_t *L,int pos)
{
	int i = pos;
	for(i;i<L->sub;i++) //记得后移
	{
		L->data[i] = L->data[i+1];
	}
	L->sub-=1;
	return true;
}
bool change_seqlist(seqlist_t *L,int x,int pos)
{
	L->data[pos] = x;
	return true;
}
int search_seqlist(seqlist_t *L,int x)
{
	int i = 0;
	for(i;i<L->sub;i++)
	{
		if(L->data[i] == x)
		{
			return i;
			break;		
		}
	}	
	return 0;
}

3>>seqlist_text.c

#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include"seqlist.h"

void main(int argc ,char* argv[])
{
	seqlist_t *L = NULL;
	L = create_seqlist();
	if(L == NULL)
	{
		printf("\ncreate_seqlist error\n");
		exit(-1);
	}
	else
	{
		printf("\ncreate_seqlist ok\n");
	}
	
	printf("\n顺序链表插入操作:");
	insert_seqlist(L,11,0);
	insert_seqlist(L,22,1);
	insert_seqlist(L,33,2);
	insert_seqlist(L,44,3);
	insert_seqlist(L,55,4);
	printf("\n");
	show_seqlist(L);


	printf("\n顺序链表查找操作:");
	printf("\n查找44:%d位置\n",search_seqlist(L,44));

	printf("\n顺序链表修改操作:");
	change_seqlist(L,88,0);
	change_seqlist(L,88,1);
	change_seqlist(L,88,2);
	change_seqlist(L,88,3);
	change_seqlist(L,88,4);
	show_seqlist(L);

	printf("\n顺序链表删除操作:");
	delete_seqlist(L,0);
	delete_seqlist(L,1);
	delete_seqlist(L,2);
	delete_seqlist(L,3);
	delete_seqlist(L,4);
	printf("\n");
	show_seqlist(L);
	
	printf("\n释放顺序列表");
	clear_seqlist(L);
	
}

4>>Makefile

seqlist_text:seqlist.o seqlist_text.c
        gcc seqlist.o seqlist_text.c -o seqlist_text

seqlist.o:seqlist.c seqlist.h
        gcc seqlist.c -c -o seqlist.o

.PHONY:clean
clean:
        rm -rf seqlist.o seqlist_text                           
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值