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