首页 > 代码库 > 利用数组创建的顺序表实现各种功能

利用数组创建的顺序表实现各种功能

主函数main.c

#include "func.h"
#define MAXSIZE 100
INT32 main(
		  void
		  )
{
	INT32 temp[MAXSIZE] = {NULL}, f = 0, OSM = 1;
	OSM = create_SL (temp);
	do
	{
		OSM = OSM_Printf("\n\t========================================\n");
		OSM = OSM_Printf("\t=============请选择功能选项:============\n");
		OSM = OSM_Printf("\t===============1、插入元素===============\n");
		OSM = OSM_Printf("\t===============2、删除元素===============\n");
		OSM = OSM_Printf("\t===============3、追加元素===============\n");
		OSM = OSM_Printf("\t===============4、获取元素===============\n");
		OSM = OSM_Printf("\t===============5、查找元素===============\n");
		OSM = OSM_Printf("\t===============6、清空元素===============\n");
		OSM = OSM_Printf("\t===============7、判断是否空=============\n");
		OSM = OSM_Printf("\t===============8、判断是否已满===========\n");
		OSM = OSM_Printf("\t===============9、统计元素的个数=========\n");
		OSM = OSM_Printf("\t===============0、退出===================\n");
		OSM = OSM_Printf("\t**************** 选择数字 ***************\n");
		f = scanf_for();
		switch(f)
		{
		case 1:
			OSM = Insert_SL (temp);
			break;
		case 2:
			OSM = Delete_SL (temp);
			break;
		case 3:
			OSM = add_SL (temp);
			break;
		case 4:
			OSM = get_SL (temp);	
			break;
		case 5:
			OSM = find_SL (temp);
			break;
		case 6:
			OSM = clear_SL (temp);
			break;
		case 7:
			OSM = empty_SL (temp);
			break;
		case 8:
			OSM = full_SL (temp);
			break;
		case 9:
			OSM = number_SL (temp);
			break;
		case 0:
			break;
		default:
			OSM = OSM_Printf("输入数据是非法的!!!!\n");
			break;
		}	
	}while (0 != f);
	return 0;
}
功能函数:func.c

#include "func.h"
#define MAXSIZE 100											/* 开始限定这个顺序表的大小 */


INT32 create_SL(INT32 a[])									/* 创建 */
{
	INT32 OSM = 1, i32num = 0, i32 = 0;			
	
	OSM = OSM_Printf("请输入要创建链表中元素的个数:\n");		
	i32num = scanf_for();
	
	if ( (0 > i32num) || (MAXSIZE < i32num) )				/* 创建的条件 */
	{
		OSM = OSM_Printf(" 非法的数据\n");
	}
	else
	{
		OSM = OSM_Printf("输入相关的元素:\n");
		for ( i32 = 0; i32 < i32num; i32++)					/* 输入的元素 */
		{
			a[i32] = scanf_for();
		}
	}
	OSM = OSM_Printf("已经创建了表\n");
	OSM = OSM_Printf("表为:");
	for ( i32 = 0; i32 < i32num; i32++)					/* 打印出来 */
	{
		if ( NULL != a[i32] )
		{
			OSM = OSM_Printf(" %d \t",a[i32]);
		}
	}
	i32length = i32;
	return *a;
}
INT32 Insert_SL(INT32 b[])
{
	/* 定义的标识符, 输入的位置, 数组的长度, 插入的数据,循环体变量 */
	INT32 OSM = 1, i32Insert_position = 0, i32Insert_data = http://www.mamicode.com/0, i32j = 0;>
花费了几天的时间终于达到要求了。所有的代码都可以通过MISRA C的检测。并且功能良好

利用数组创建的顺序表实现各种功能