顺序表基本操作

#include"common.h"
#include"seqlist.h"
#include"slist.h"

int main(int argc, char *argv[])
{
//SeqList mylist;

SListNode *p = NULL;
SList mylist;
SListInit(&mylist);

DataType item;
int pos, index;
BOOL flag;
int select = 1;
while (select)
{
	printf("************************************\n");
	printf("* [1] push_back     [2] push_front *\n");
	printf("* [3] show_list     [0] quit_system*\n");
	printf("* [4] pop_back      [5] pop_front  *\n");
	printf("* [6] find_pos      [7] find_val   *\n");
	printf("* [8] insert_pos    [9] delete_val *\n");
	printf("* [10] delete_pos   [11]length     *\n");
	printf("* [12] remove_all   [13] reverse   *\n");
	printf("* [14] sort         [15] clear     *\n");
	printf("************************************\n");
	printf("请选择:>");
	scanf("%d", &select);
	if (select == 0)
		break;
	switch (select)
	{
	case 1:
		printf("请输入要插入的数据(以-1结束):>");
		while (scanf("%d", &item), item != -1)
		{
			SListPushBack(&mylist, item);
		}
		break;
	case 2:
		printf("请输入要插入的数据(以-1结束):>");
		while (scanf("%d", &item), item != -1)
		{
			SListPushFront(&mylist, item);
		}
		break;
	case 3:
		SListShow(&mylist);
		break;
	case 4:
		//SeqListPopBack(&mylist);
		break;
	case 5:
		//SeqListPopFront(&mylist);
		break;
	case 6:
		printf("请输入要查询的位置:>");
		scanf("%d", &pos);
		//printf("要查询的数据:%d\n", SeqListFindByPos(&mylist, pos));
		break;
	case 7:
		printf("请输入要查询的数据:>");
		scanf("%d", &item);
		//index = SeqListFindByVal(&mylist, item);
		p = SListFindByVal(&mylist, item);
		if (p==NULL)
			printf("要查询的数据%d不存在.\n", item);
		break;
	case 8:
		printf("请输入要插入的位置:>");
		scanf("%d", &pos);
		printf("请输入要插入的数据:>");
		scanf("%d", &item);
		//flag = SeqListInsertByPos(&mylist, pos, item);
		if (flag)
			printf("插入成功.\n");
		else
			printf("插入失败.\n");
		break;
	case 9:
		printf("请输入要删除的数据:>");
		scanf("%d", &item);
		//flag = SeqListEraseByVal(&mylist, item);
		SListEraseByVal(&mylist, item);
		break;
	case 10:
		printf("请输入要删除的位置:>");
		scanf("%d", &pos);
		//flag = SeqListEraseByPos(&mylist, pos);
		if (flag)
			printf("删除成功.\n");
		else
			printf("删除失败.\n");
		break;
	case 11:
		printf("SeqList Length = %d\n", SeqListLength(&mylist));
		break;
	case 12:
		printf("请输入要删除的数据:>");
		scanf("%d", &item);
		//SeqListRemoveAll(&mylist, item);
		break;
	case 13:
		//SeqListReverse(&mylist);
		break;
	case 14:
		//SeqListSort(&mylist);
		break;
	case 15:
		//SeqListClear(&mylist);
		break;
	}
}

//SeqListDestroy(&mylist);
return 0; 

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值