<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      C語言【數(shù)據(jù)結(jié)構(gòu)】線性表--順序表

      sqlist.h
      #include <stdio.h>
      #define N 128
      typedef int data_type;
      
      typedef struct {
      	data_type data[N];
      	int last;
      }sqlist;
      
      // 創(chuàng)建表
      sqlist * list_create();
      // 插入表元素
      int list_insert(sqlist * L, data_type value, int pos);
      int list_head_insert(sqlist * L, data_type value);
      int list_append(sqlist * L, data_type value);
      // 修改表元素
      int list_modify(sqlist * L, data_type value, int pos);
      // 刪除表元素
      int list_delete(sqlist * L, int pos);
      // 查找表元素位置
      int list_find_elem(sqlist * L, data_type value);
      // 打印表
      int list_show(sqlist * L);
      // 清空表
      int list_clear(sqlist * L);
      // 銷毀表
      int list_destory(sqlist * L);
      // 表判空
      int list_is_empty(sqlist * L);
      // 表長度
      int list_length(sqlist * L);
      // 表合并,且表2與表1有重復(fù)的不合并
      int list_merge(sqlist * L1, sqlist * L2);
      // 去重
      int list_remove_duplicate(sqlist * L);
      // 表排序
      int list_sort(sqlist * L);
      
      sqlist.c
      #include <stdio.h>
      #include <stdlib.h>
      #include <string.h>
      #include "sqlist.h"
      
      sqlist * list_create(){
      	sqlist * L; // 指向隨機(jī)的一個(gè)地址,需要申請一塊內(nèi)存
      	L = (sqlist *)malloc(sizeof(sqlist));
      	if(L == NULL){
      		printf("%s\n", "malloc failed");
      		return L;
      	}
      	// 該內(nèi)存空間需要初始化下
      	memset(L, 0, sizeof(sqlist));
      	L->last = -1;
      
      	return L;
      }
      
      // 指定索引插入
      int list_insert(sqlist * L, data_type value, int pos){
      	int i;
      	
      	if (L==NULL){
      		printf("%s\n", "list not create");
      		return -1;
      	}
      	// list is full
      	if (L->last == N - 1){
      		printf("%s\n","list_insert failed, list is full");
      		return -1;
      	}
      	// pos范圍應(yīng)該是[0, last+1],其中注意last=-1的極限值
      	if (pos<0 || pos > L->last+1){
      		printf("%s\n","pos is invalid");
      		return -1;
      	}
      	// 元素移動,先將下標(biāo)最大的移動到后邊
      	for (i = L->last; i>= pos; i--){
      		L->data[i+1] = L->data[i];
      	}
      	L->data[pos] = value;
      	L->last++;
      	return 0;
      }
      
      // 頭插
      int list_head_insert(sqlist * L, data_type value){
      	int i;
      	if (L==NULL){
      		printf("%s\n", "list not create");
      		return -1;
      	}
      	// list is full
      	if (L->last == N - 1){
      		printf("%s\n","list_head_insert failed, list is full");
      		return -1;
      	}
      	for (i = L->last; i >=0; i--){
      		L->data[i+1] = L->data[i];
      	}
      	L->data[0] = value;
      	L->last++;
      	return 0;
      }
      // 尾部追加
      int list_append(sqlist * L, data_type value){
      	if (L==NULL){
      		printf("%s\n", "list not create");
      		return -1;
      	}
      	// list is full
      	if (L->last == N - 1){
      		printf("%s\n","list_append failed, list is full");
      		return -1;
      	}
      	L->last++;
      	L->data[L->last] = value;
      	return 0;
      }
      
      // 修改指定索引的值
      int list_modify(sqlist * L, data_type value, int pos){
      	if(L==NULL){
      		printf("%s\n", "list not create");
      		return -1;
      	}
      	if(L->last == -1){
      		printf("%s\n", "list_modify failed, list is empty");
      		return -1;
      	}
      	// pos范圍應(yīng)該是[0, last+1]
      	if (pos<0 || pos > L->last){
      		printf("%s\n","pos is invalid");
      		return -1;
      	}
      	L->data[pos] = value;
      	return 0;
      }
      
      // 刪除指定索引的元素
      int list_delete(sqlist * L, int pos){
      	if(L==NULL){
      		printf("%s\n", "list not create");
      		return -1;
      	}
      	if(L->last == -1){
      		printf("%s\n", "list_delete failed, list is empty");
      		return -1;
      	}
      	// pos范圍應(yīng)該是[0, last]
      	if (pos<0 || pos > L->last){
      		printf("%s\n","pos is invalid");
      		return -1;
      	}
      	int i;
      	// 前移
      	for (i = pos; i <= L->last; i++){
      		L->data[i] = L->data[i+1];
      	}
      	L->last--;
      	return 0;
      }
      
      int list_find_elem(sqlist * L, data_type value){
      	if (L==NULL){
      		printf("%s\n", "list not create");
      		return -1;
      	}
      	int i;
      	for (i = 0; i <= L->last; i++){
      		if(L->data[i]==value){
      			return i;
      		}
      	}
      	return -1;
      }
      
      int list_show(sqlist * L){
      	int i;
      	if (L==NULL){
      		printf("%s\n", "list not create");
      		return -1;
      	}
      	for (i = 0; i <= L->last; ++i){
      		printf("%d ", L->data[i]);
      	}
      	puts("");
      	return 0;
      }
      // 清空表
      int list_clear(sqlist * L){
      	if(L==NULL){
      		printf("%s\n", "list not create");
      		return -1;
      	}
      	if(L->last == -1){
      		return 0;
      	}
      	memset(L, 0, sizeof(sqlist));
      	L->last = -1;
      	return 0;
      }
      // 有問題
      int list_destory(sqlist * L){
      	if(L==NULL){
      		printf("%s\n", "list not create");
      		return -1;
      	}
      	free(L);
      	L = NULL;
      	return 0;
      }
      
      /*
      	list_is_empty: is list empty?
      	para L: list
      	ret: 1-empty 0-not empty
      */
      int list_is_empty(sqlist * L){
      	if(L==NULL){
      		printf("%s\n", "list not create");
      		return -1;
      	}
      	if(L->last == -1){
      		return 1;
      	}
          return 0;
      }
      
      int list_length(sqlist * L){
      	if(L==NULL){
      		printf("%s\n", "list not create");
      		return -1;
      	}
      	return L->last+1;
      }
      
      
      int list_merge(sqlist * L1, sqlist * L2){
      	if(L1==NULL && L2==NULL){
      		printf("%s\n", "list not create");
      		return -1;
      	}
      	int i;
      	for (i = 0; i <= L2->last; i++){
      		int ret1 = list_find_elem(L1, L2->data[i]);
      		if(ret1 == -1){
      			int ret2 = list_append(L1, L2->data[i]);
      			if(ret2==-1){
      				return -1;
      			}
      		}
      	}
      }
      
      
      int list_remove_duplicate(sqlist * L){
      	if(L==NULL){
      		printf("%s\n", "list not create");
      		return -1;
      	}
      	int i , j;
      	for (i = 0; i <= L->last; i++){
      		for (j = i+1; j <= L->last; j++){
      			if (L->data[i] == L->data[j]){
      				list_delete(L, j);
      				j--;
      			}
      		}
      	}
          return 0;
      }
      int list_sort(sqlist * L){
      	if (L==NULL){
      		return -1;
      	}
      	int i, j;
      	data_type t;
      	for (i = 0; i <= L->last; i++){
      		for (j = i+1; j <= L->last; j++){
      			if(L->data[j] < L->data[i]){
      				t = L->data[i];
      				L->data[i] = L->data[j];
      				L->data[j] = t;
      			}
      		}
      	}
      	return 0;
      }
      
      test.c
      #include <stdio.h>
      #include "sqlist.h"
      
      int main(int argc, char const *argv[])
      {
      	sqlist * L2;
      	L2 = list_create();
      	list_insert(L2, 60, 0);
      	list_remove_duplicate(L2);
      	
      	list_show(L2);
      	return 0;
      }
      
      posted @ 2023-09-21 20:40  揚(yáng)帆去遠(yuǎn)航  閱讀(108)  評論(0)    收藏  舉報(bào)
      主站蜘蛛池模板: 精品亚洲成A人在线观看青青| 视频一区视频二区视频三区| 少妇高潮尖叫黑人激情在线| 亚洲欧美中文字幕日韩一区二区 | 久热re这里精品视频在线6| 赣州市| 72种姿势欧美久久久久大黄蕉| 久久国产精品不只是精品| 亚洲熟妇自偷自拍另欧美| 吉首市| 国产又爽又黄又无遮挡的激情视频| 国产精品视频一品二区三| 久久精品国产一区二区三| 2020国产欧洲精品网站| 亚洲国产精品久久久天堂麻豆宅男 | 国产丰满麻豆videossexhd| 一本加勒比hezyo无码人妻| 国精品午夜福利视频不卡| 姐姐6电视剧在线观看| 国产av激情无码久久| 亚洲精品一区二区二三区| 久青草视频在线观看免费| 欧美大胆老熟妇乱子伦视频 | 邵阳市| 久久亚洲精品中文字幕无| 国产AV福利第一精品| 综合色天天久久| 亚洲中文字幕在线无码一区二区| 色成人精品免费视频| 国产成人一区二区三区免费| 亚洲日韩国产成网在线观看| 中文字幕 日韩 人妻 无码| 国产午夜福利一区二区三区| 亚洲色欲色欲天天天www| 91精品国产午夜福利| 无码专区人妻系列日韩精品少妇| 777奇米四色成人影视色区| 国产精品一二三中文字幕| 日韩一区二区三区女优丝袜| 色8久久人人97超碰香蕉987| 亚洲天堂激情av在线|