线性表的初始化,增删查操作等

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/fzz19960915/article/details/80370241

线性表的初始化,增删查操作等

#include<stdio.h>
#define LISTSIZE 100
typedef int DataType;

typedef struct{
	DataType items[LISTSIZE];
	int length;
}SqList; 


// 2-1 init list

int InitList(SqList *L){
	L->length = 0;
	return 1;
}

// 2-2 length
int ListLength(SqList L){
	return L.length;
}

// 2-3 empty
int ListEmpty(SqList L){
	if(L.length <= 0) return 1;
	else return 0;
}

// 2-4 insert

int ListInsert(SqList *L,int pos,DataType item){
	int i;
	if(L->length >= LISTSIZE){
		printf("it had full,you can insert it\n");
		return 0;
	}

	if(pos<=0 || pos>L->length+1){
		printf("you choose position is nosuitbale,please choose the [1,length+1]\n");
		return 0;
	}

	for(i = L->length -1;i>=pos-1;i--){
		L->items[i+1] = L->items[i];
	}

	L->items[pos-1] = item;
	L->length++;
	return 1;
}


// 2-5 delete
int ListDelete(SqList *L,int pos,DataType *item){
	int i;
	if(ListEmpty(*L)){
		printf("this is a empty List\n");
		return 0;
	}

	if(pos<1||pos>L->length){
		printf("delete the position is nosuitbale,the range is [1,length]\n");
		return 0;
	}

	*item = L->items[pos-1];
	for (int i = 0; i < L->length; ++i)
	{
		L->items[i-1] = L->items[i];
		/* code */
	}
	L->length --;
	return 1;
}


// 2-6 find

int Find(SqList L,DataType item){
	int pos =0;
	if(ListEmpty(L)){
		printf("this is a empty List\n");
		return 0;
	}

	while(pos<L.length && L.items[pos]!=item){
		pos++;
	}

	if(pos<L.length) return pos+1;
	else return 0;
}

// 2-7 get element

int GetElem(SqList L,int pos,DataType *item){
	if(ListEmpty(L)) return 0;

	if(pos<0 || pos>L.length){
		printf("please input again!\n");
		return 0;
	}

	*item = L.items[pos-1];
	return 1;
}


// 2-8 TraverseList

int TraverseList(SqList L){
	int i;
	for(i = 0 ; i <L.length;i++){
		printf("%d\t",L.items[i] );
	}
	printf("\n");
	return 0;
}


int main(){

	int i;
	int data[7] = {0,1,1,2,3,5,8};
	DataType item;
	SqList fibo;
	printf("init list\n");
	InitList(&fibo);

	for(i = 0; i < 7;i++){
		if(!ListInsert(&fibo,i+1,data[i])){
			printf("run wrong\n");
			return 0;
		}
	}

	printf("\nbefore delete \n");
	TraverseList(fibo);

	if(!ListDelete(&fibo,7,&item)){
		printf("run wrong\n");
		return 0;
	}



	printf("\nafter delete \n");
	TraverseList(fibo);
	return 1;

}


展开阅读全文

Restful API接口举例 :队列的增删操作

05-25

<div>n <span style="font-size:16px;"><span><span style="font-size:20px;color:#FF0000;"><strong><span>课程亮点:</span></strong></span></span></span> n</div>n<div style="font-size:16px;">n <span style="color:#424242;"><span style="background-color:#FFFAA5;">课程培训详细的笔记以及实例代码,让学员开始掌握RabbitMQ知识点</span></span> n</div>n<p style="font-size:16px;">n <span style="font-size:14px;"><span><span style="background-color:#FFFFFF;"><span style="color:#424242;"><br /></span></span></span></span> n</p>n<p>n </p><div>n <span style="font-size:16px;"><span><strong><span style="background-color:#FFFFFF;">课程内容:</span></strong></span></span> n </div>n <p>n <span style="font-size:16px;color:#E53333;"><strong> </strong></span><span style="font-size:16px;color:#E53333;"><strong>第5章:RabbitMQ管理:虚拟主机管理、用户管理、权限管理、角色管理、各种查看命令、Restful的API接口、应用管理</strong></span>n </p>n <p>n <span style="font-size:16px;color:#E53333;"><strong><br /></strong></span>n </p>nn<div style="font-size:16px;">n <span style="color:#FF0000;"><strong><span style="font-size:18px;">课程特色:</span></strong></span> n</div>n<div>n <ol><li>n 笔记RabbitMQ中间件 :用200多条笔记串连所有知识点,让学员从一点一滴积累,学习过程无压力n </li>n <li>n 笔记标题采用关键字标识法,帮助学员更加容易记住知识点n </li>n <li>n 笔记以超链接形式让知识点关联起来,形式知识体系n </li>n <li>n 采用先概念后实例再应用方式,知识点深入浅出n </li>n <li>n <strong>提供授课内容笔记作为课后复习以及工作备查工具</strong> n </li>n </ol></div>n<p>n <span style="font-size:16px;"><span><span style="color:#00B050;"><strong><strong><span style="font-size:18px;">部分图表(电脑PC端查看):</span></strong></strong></span></span></span> n</p>n<p>n <span style="font-size:16px;"><span><span style="color:#00B050;"><strong><strong><span style="font-size:18px;"><img src="https://img-bss.csdn.net/201905251321158453.png" alt="" /><img src="https://img-bss.csdn.net/201905251321219671.png" alt="" /><img src="https://img-bss.csdn.net/201905251321269846.png" alt="" /><img src="https://img-bss.csdn.net/201905251321324031.png" alt="" /><img src="https://img-bss.csdn.net/201905251321379707.png" alt="" /><img src="https://img-bss.csdn.net/201905251321434920.png" alt="" /><img src="https://img-bss.csdn.net/201905251321471797.png" alt="" /><br /></span></strong></strong></span></span></span> n</p>

没有更多推荐了,返回首页