順序表:
sqlist.h:
/* * sqlist.h */ #ifndef SQLIST_H_ #define SQLIST_H_ #define OK 1 #define ERROR -1 #define MAXSZ 50 typedef int ElemType; typedef struct { ElemType elem[MAXSZ]; int length; } sqlist; int InitSqlist(sqlist *L); int ListEmpty(const sqlist *L); int ListLength(const sqlist *L); int PrintList(const sqlist *L); int GetElem(const sqlist *L, const int i, ElemType *e); int LocateElem(const sqlist *L, ElemType x); int ListInsert(sqlist *L, const int i, const ElemType e); int ListDelete(sqlist *L, const int i, ElemType *e); int PriorElem(const sqlist *L, const ElemType x, ElemType *e); int NextElem(const sqlist *L, const ElemType x, ElemType *e); int ReverseSqlist(sqlist *L); #endif /* SQLIST_H_ */
sqlist.c:
/* * sqlist.c */ #include "sqlist.h" #include <stdio.h> int InitSqlist(sqlist *L) { if (L != NULL) { L->length = 0; return OK; } else { return ERROR; } } int ListEmpty(const sqlist *L) { if (L != NULL) { return (0 == L->length); } else { return ERROR; } } int ListLength(const sqlist *L) { if (L != NULL) { return (L->length); } else { return ERROR; } } int PrintList(const sqlist *L) { if (NULL == L || ListEmpty(L)) { printf("ERROR: The list is NULL or empty!/n"); return ERROR; } else { printf("====================/n"); int i; for (i = 0; i < L->length; i++) { printf("%d/n", L->elem[i]); } printf("====================/n"); return OK; } } int GetElem(const sqlist *L, const int i, ElemType *e) { if (NULL == L || i > L->length || i < 1) { printf("ERROR: The list is NULL/empty or the position is invalid!/n"); return ERROR; } else { *e = L->elem[i - 1]; return OK; } } int LocateElem(const sqlist *L, ElemType x) { if (NULL == L || ListEmpty(L)) { printf("ERROR: The list is NULL or empty!/n"); return ERROR; } else { int i = 0; while (i < L->length && L->elem[i] != x) { i++; } if (i >= L->length) { printf("ERROR: The elem can't be found/n"); return ERROR; } else { return i+1; } } } int ListInsert(sqlist *L, const int i, const ElemType e) { if (NULL == L || i < 1 || i > L->length + 1) { printf("ERROR: The list is NULL or the position is invalid!/n"); return ERROR; } else { int j; for (j = L->length; j > i - 1; j--) { L->elem[j] = L->elem[j - 1]; } L->elem[i - 1] = e; L->length++; return OK; } } int ListDelete(sqlist *L, const int i, ElemType *e) { if (NULL == L || i < 1 || i > L->length) { printf("ERROR: The list is NULL or the position is invalid!/n"); return ERROR; } else { *e = L->elem[i - 1]; int j; for (j = i; j < L->length; j++) { L->elem[j - 1] = L->elem[j]; } L->length--; return 0; } } int PriorElem(const sqlist *L, const ElemType x, ElemType *e) { if (NULL == L) { printf("ERROR: The list is NULL!/n"); return ERROR; } else { int i = 0; while (i < L->length && L->elem[i] != x) { i++; } if (i < 1 || i >= L->length) { printf("ERROR: The elem can't be found!/n"); return ERROR; } else { *e = L->elem[i - 1]; return OK; } } } int NextElem(const sqlist *L, const ElemType x, ElemType *e) { if (NULL == L) { printf("ERROR: The list is NULL!/n"); return ERROR; } else { int i = 0; while (i < L->length && L->elem[i] != x) { i++; } if (i < 1 || i >= L->length - 1) { printf("ERROR: The elem can't be found!/n"); return ERROR; } else { *e = L->elem[i + 1]; return OK; } } } int ReverseSqlist(sqlist *L) { if (NULL == L) { printf("Error: The list is NULL!/n"); return ERROR; } else { int i,j; ElemType temp; for(i=0,j=L->length-1;i<j;i++,j--) { temp = L->elem[i]; L->elem[i]=L->elem[j]; L->elem[j]=temp; } return OK; } }
測試的主程序文件(main函數):
SeqList.c:
/* ============================================================================ Name : SeqList.c Author : Version : Copyright : Description : Hello World in C, Ansi-style ============================================================================ */ #include <stdio.h> #include <stdlib.h> #include "sqlist.h" int main(void) { sqlist L; printf("@@@@@@@@@@@Test Insert@@@@@@@@@@/n"); InitSqlist(&L); ListInsert(&L,1,1); ListInsert(&L,2,2); ListInsert(&L,3,3); PrintList(&L); ListInsert(&L,2,22); PrintList(&L); ListInsert(&L,1,11); PrintList(&L); printf("@@@@@@@@@@@Test Delete@@@@@@@@@@/n"); int e=0; ListDelete(&L,1,&e); PrintList(&L); printf("*******/ne=%d/n******/n",e); ListDelete(&L,L.length,&e); PrintList(&L); printf("*******/ne=%d/n******/n",e); ListDelete(&L,2,&e); PrintList(&L); printf("*******/ne=%d/n******/n",e); ListInsert(&L,3,3); ListInsert(&L,1,0); PrintList(&L); printf("@@@@@@@@@@@Test locate@@@@@@@@@@/n"); LocateElem(&L, 3); printf("========/npostion is:%d/n========/n",LocateElem(&L, 3)); printf("@@@@@@@@@@@Test Piror@@@@@@@@@@/n"); PriorElem(&L, 3, &e); PriorElem(&L, 1, &e); PriorElem(&L, 2, &e); printf("========/nprior is:%d/n========/n", e); PriorElem(&L, 4, &e); printf("========/nprior is:%d/n========/n", e); PriorElem(&L, 0, &e); printf("@@@@@@@@@@@Test Next@@@@@@@@@@/n"); NextElem(&L, 3, &e); e=0; NextElem(&L, 1, &e); printf("========/nnext is:%d/n========/n", e); NextElem(&L, 2, &e); printf("========/nnext is:%d/n========/n", e); NextElem(&L, 4, &e); printf("@@@@@@@@@@@Test Reverse@@@@@@@@@@/n"); PrintList(&L); ReverseSqlist(&L); PrintList(&L); return EXIT_SUCCESS; }
pt-osc原理探索及其觸發器的深入分析 > 作者:莫善,某互聯網公司高級 DBA。 > > 愛可生開源社區出品,原創內容未經授權不得隨意使用,轉載請聯繫小編並註明來源。 > > 本文約 6000 字,預計閱讀需要 20 分鐘。 背景 自工
本文介紹了 InnoDB 支持哪幾類表鎖,以及它們分別都用在什麼場景下,還介紹了其中兩類表鎖爲什麼要存在。 作者:操盛春,愛可生技術專家,公衆號『一樹一溪』作者,專注於研究 MySQL 和 OceanBase 源碼。 愛可生開源社區出品,
這個其實是一個特別高頻的面試題,松哥也一直很想和大家仔細來聊一聊這個話題,網上關於這塊的文章很多,但是我一直覺得要把這個問題講清楚還有點難度,今天我來試一試,看能不能和小夥伴們把這個問題梳理清楚,當然,如果小夥伴們覺得看文章不過癮,松哥也有
分享8個開箱即用的API,方便日常處理集合。 1. 快速過濾空值:Stream.ofNullable 該方法是在 Java 9 中引入的,有助於過濾集合中的所有空值,從而可能使我們避免空指針異常。 在下面的示例中,有一個包含 null 的L
一、背景 在日常部門OpsReview過程中,部門內多次遇到應用容器所在的宿主機磁盤繁忙導致的接口響應緩慢,TP99增高等影響服務性能的問題,其中比較有效的解決方案是開啓日誌的異步打印,可以有效避免同步日誌打印在磁盤IO高起的情況下拖慢業
本文分享自華爲雲社區《【MySQL技術專欄】MySQL8.0直方圖介紹》,作者:GaussDB 數據庫。 背景 數據庫查詢優化器負責將SQL查詢轉換爲儘可能高效的執行計劃,但因爲數據環境不斷變化導致優化器對查詢數據瞭解的不夠充足,可能無法
每篇一句 大魔王張怡寧:女兒,這堆金牌你拿去玩吧,但我的銀牌不能給你玩。你要想玩銀牌就去找你王浩叔叔吧,他那銀牌多 前言 爲了講述好Spring MVC最爲複雜的數據綁定這塊,我前面可謂是做足了功課,對此部分知識此處給小夥伴留一個學
作者:vivo 互聯網數據庫團隊- Qiu Xinbo 本文主要通過圖示介紹了用主鍵進行分片查詢的過程,介紹了主鍵分頁查詢存在SQL性能問題,如何去創建高效的索引去優化主鍵分頁查詢的SQL性能問題 對於數據分佈不均
JSON簡介: JSON(Java Script Object Notation)是一種輕量級的數據交換格式,通常用於在不同系統之間傳輸數據。它基於 JavaScript 對象語法,但已成爲一種獨立於語言的格式。JSON 數據以鍵值對的形式
一、簡單介紹: CaffeineCache和Guava的Cache是應用廣泛的本地緩存。 在開發中,爲了達到降低依賴、提高訪問速度的目的。會使用它存儲一些維表接口的返回值和數據庫查詢結果,在有些場景下也會在分佈式緩存上再加上一層本地緩存,
作者:vivo 互聯網大前端團隊 - Ma Lian 本文主要描述了FileProvider,startAnyWhere實現,Parcel不對稱漏洞以及這三者結合產生的漏洞利用實戰,另外闡述了漏洞利用的影響和修復預防措施,這個漏洞波及了
繼續運行 🥋 回憶上次內容 上上次 真寫了 萬行 代碼 這 萬行 代碼 都是寫在 明面 上的 這次 使用git命令 下載了 github上面的倉庫
Java將List結果分成3份執行 在Java編程中,有時候我們需要將一個List集合中的元素分成幾部分進行處理。這種情況下,我們可以使用Java的相關類庫和API來實現這一需求。在本文中,我們將介紹如何使用Java將List結果分成3份執
本文分享自華爲雲社區《一文徹底喫透MyBatis源碼!!》,作者:冰 河。 寫在前面 隨着互聯網的發展,越來越多的公司摒棄了Hibernate,而選擇擁抱了MyBatis。而且,很多大廠在面試的時候喜歡問MyBatis底層的原理和源碼實現
原方法 /** * 動態更新form * @param form */ updateForm(form) { this.form.manholeId = form.manholeId; this.form