順序表(代碼、分析、匯編)

目錄:

    • 代碼:
    • 分析:
    • 匯編:

代碼:

SeqList.h

#ifndef _SEQLIST_H_ 
#define _SEQLIST_H_ typedef void SeqList; //定義鏈表數據類型,void因為要適用不同鏈表數據類型 
typedef void SeqListNode;  //定義鏈表節點類型 void因為要適用不同節點類型 SeqList* SeqList_Create(int capacity);//聲明創建鏈表函數void SeqList_Destroy(SeqList* list); //聲明刪除鏈表函數void SeqList_Clear(SeqList* list);//聲明獲取鏈表當前長度函數int SeqList_Length(SeqList* list);//聲明獲取鏈表當前長度函數int SeqList_Capacity(SeqList* list);//聲明獲取鏈表容量函數int SeqList_Insert(SeqList* list, SeqListNode* node, int pos);//聲明插入數據函數SeqListNode* SeqList_Get(SeqList* list, int pos);//聲明獲取數據函數SeqListNode* SeqList_Delete(SeqList* list, int pos);//聲明刪除一個數據函數#endif

SeqList.c

#include <stdio.h>
#include <malloc.h>
#include "SeqList.h"typedef unsigned int TSeqListNode; typedef struct _tag_SeqList
{int capacity;int length;TSeqListNode* node; //鏈表類型中存放指向數據的指針(數組)
} TSeqList;   //定義鏈表數據類型 SeqList* SeqList_Create(int capacity) //定義創建鏈表函數 根據參數容量創建
{TSeqList* ret = NULL;if( capacity >= 0 ){ret = (TSeqList*)malloc(sizeof(TSeqList) + sizeof(TSeqListNode) * capacity);}if( ret != NULL ) //成功{ret->capacity = capacity;  //賦值容量ret->length = 0;  //當前長度 下標ret->node = (TSeqListNode*)(ret + 1);//加1 剛好是數組首元素地址}return ret; //返回自定義的鏈表數據類型
}void SeqList_Destroy(SeqList* list) //定義刪除鏈表函數
{free(list);
}void SeqList_Clear(SeqList* list)//定義清除鏈表長度重設為0
{TSeqList* sList = (TSeqList*)list;if( sList != NULL ){sList->length = 0;}
}int SeqList_Length(SeqList* list) //定義獲取鏈表當前長度函數
{TSeqList* sList = (TSeqList*)list;int ret = -1;if( sList != NULL ){ret = sList->length;}return ret;
}int SeqList_Capacity(SeqList* list) //定義獲取鏈表容量函數
{TSeqList* sList = (TSeqList*)list;int ret = -1;if( sList != NULL ){ret = sList->capacity;}return ret;
}int SeqList_Insert(SeqList* list, SeqListNode* node, int pos) //定義插入數據函數
{TSeqList* sList = (TSeqList*)list;int ret = (sList != NULL);int i = 0;ret = ret && (sList->length + 1 <= sList->capacity); //判斷鏈表是否滿了ret = ret && (0 <= pos); //判斷要插入的位置不能小于0if( ret )  //上面條件滿足{if( pos >= sList->length ) //是否大于當前的長度下標{pos = sList->length;  //表示直接插入的位置就是最后一個}for(i=sList->length; i>pos; i--) //循環元素后移{sList->node[i] = sList->node[i-1];}sList->node[i] = (TSeqListNode)node;//將鏈表數據的地址轉成數值賦值到元素sList->length++; //長度增加}return ret;
}SeqListNode* SeqList_Get(SeqList* list, int pos) //定義獲取數據函數
{TSeqList* sList = (TSeqList*)list;SeqListNode* ret = NULL;if( (sList != NULL) && (0 <= pos) && (pos < sList->length) ) //判斷不能超出范圍{ret = (SeqListNode*)(sList->node[pos]); //移到指針 指針的值就是地址轉成的數值,再轉回指針}return ret;
}SeqListNode* SeqList_Delete(SeqList* list, int pos) //定義刪除一個數據函數
{TSeqList* sList = (TSeqList*)list;SeqListNode* ret = SeqList_Get(list, pos); //將數據獲取出來int i = 0;if( ret != NULL ){for(i=pos+1; i<sList->length; i++)//循環將元素前移{sList->node[i-1] = sList->node[i];}sList->length--;//當前長度減少}return ret;
}

smain.c

#include <stdio.h>
#include <stdlib.h>
#include "SeqList.h"int main(int argc, char *argv[]) 
{SeqList* list = SeqList_Create(5);int i = 10;int j = 11;int k = 12;int x = 13;int y = 14;int z = 15;int index = 0;SeqList_Insert(list, &i, 0);SeqList_Insert(list, &j, 0);SeqList_Insert(list, &k, 0);SeqList_Insert(list, &x, 0);SeqList_Insert(list, &y, 0);SeqList_Insert(list, &z, 0);for(index=0; index<SeqList_Length(list); index++){int* p = (int*)SeqList_Get(list, index);printf("%d\n", *p);}printf("\n");while( SeqList_Length(list) > 0 ){int* p = (int*)SeqList_Delete(list, 0);printf("%d\n", *p);}SeqList_Destroy(list);getchar();return 0;
}

分析:

在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述

匯編:

在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/379284.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/379284.shtml
英文地址,請注明出處:http://en.pswp.cn/news/379284.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

設有兩個16位整數變量A和B,試編寫完成下述操作的程序。

設有兩個16位整數變量A和B&#xff0c;試編寫完成下述操作的程序。 &#xff08;1&#xff09;若有兩個數中一個是奇數&#xff0c;則將奇數存入A中&#xff0c;偶數存入B中。 &#xff08;2&#xff09;若兩個數均為奇數&#xff0c;則兩數分別減1&#xff0c;并存回原變量中…

棋牌游戲服務器架構: 詳細設計(三) 數據庫設計

主要有3類Database: ServerInfoDB,UserInfoDB和GameDB。 ServerInfoDB主要存儲的是游戲列表的信息,UserInfoDB存儲玩家的全局信息&#xff0c;而GameDB就是積分以及積分變化情況。下面分別加以描述。 1. ServerInfoDB ServerInfoDB主要存儲游戲列表信息。主要有以下幾個表: 1. …

程序開發與性格特征

程序開發與性格特征 引言&#xff1a; 程序員給很多人的印象一般是不善于交際、表情嚴肅、思維緊密、做事認真、沉著冷靜等等。那么這些特征到底和程序開發有沒有關系呢&#xff1f;不同性格的人在團隊開發當中將面臨什么樣的問題以及不同性格的人在團隊開發中又將發揮著什么樣…

匯編語言編寫程序從1加到100要求使用循環結構。

匯編語言編寫程序從1加到100要求使用循環結構。 匯編思路&#xff1a;AX用于存放每次累加的結果—>09998…0 首先&#xff0c;DATA段中定義SUM用來存放結果和&#xff0c;STACK段定義一個200DB類型空間&#xff0c;用來存放數據。CODE段&#xff0c;AX清0&#xff0c;CX賦值…

c語言指針++_C ++此指針| 查找輸出程序| 套裝3

c語言指針Program 1: 程序1&#xff1a; #include <iostream>using namespace std;class Test {int VAL;public:Test(int v){VAL v;}Test* Sum(Test T1, Test T2){VAL T1.VAL T2.VAL;return this;}void print(){cout << VAL << " ";}};int mai…

線性表(代碼、分析、匯編)

目錄&#xff1a;代碼&#xff1a;分析&#xff1a;匯編&#xff1a;代碼&#xff1a; LinkList.h #ifndef _LINKLIST_H_ #define _LINKLIST_H_typedef void LinkList; //定義線性表類型 typedef struct _tag_LinkListNode LinkListNode;//定義線性表節點類型 struct _tag_Li…

WPF 操作 richTextBox

FROM:http://blog.csdn.net/wuzhengqing1/article/details/7010902 取出richTextBox里面的內容 第一種方法&#xff1a; 將richTextBox的內容以字符串的形式取出 string xw System.Windows.Markup.XamlWriter.Save(richTextBox.Document); 第二種方法&#xff1a;將richTe…

微軟企業庫4.1學習筆記(八)創建對象 續集2

3.3通過配置指定和Unity的整合 另外一種方法是在配置源中指定配置的需要&#xff0c;你可以指定下面的一條或者多條&#xff1a; 你可以在Unity配置中指定想要的BlockExtensions  你可以在Unity配置中的type配置節指定如何創建企業庫對象&#xff0c;指定類型映射的關系&…

已知有幾個數據存放在BUF為首址的字節存儲區中,試統計其中正數的個數,并將結果存入ZNUM單元中。

已知有幾個數據存放在BUF為首址的字節存儲區中&#xff0c;試統計其中正數的個數&#xff0c;并將結果存入ZNUM單元中。 P160 例4.17 匯編思路&#xff1a;DATA段&#xff0c;定義BUF存儲區&#xff0c;定義一下DB類型的數據&#xff0c;N為定義數據的總個數&#xff0c;ZNUM…

靜態鏈表(代碼、分析、匯編)

目錄&#xff1a;代碼&#xff1a;分析&#xff1a;匯編&#xff1a;代碼&#xff1a; StaticList.h #ifndef _STATICLIST_H_ #define _STATICLIST_H_typedef void StaticList; //空類型靜態表類型可以接收任何類型的靜態表類型 typedef void StaticListNode;//空類型節點類型…

c語言 typedef_C Typedef-能力傾向問題與解答

c語言 typedefC programming Typedef Aptitude Questions and Answers: In this section you will find C Aptitude Questions and Answers on typedef topics, defining/changing name of any data type, using and accessing the typedef values. C編程Typedef Aptitude問答&…

ios程序 調試log宏的添加

#ifdef DEBUG # define LOG(...) NSLog(__VA_ARGS__) # define LOG_CURRENT_METHOD NSLog("%-%", NSStringFromClass([self class]), NSStringFromSelector(_cmd)) #else # define LOG(...) ; # define LOG_CURRENT_METHOD ; #endif 使用 LOG_CURRENT_METHOD; NS…

Python的線程池實現

代碼 1 #coding:utf-82 3 #Python的線程池實現4 5 importQueue6 importthreading7 importsys8 importtime9 importurllib10 11 #替我們工作的線程池中的線程12 classMyThread(threading.Thread):13 def__init__(self, workQueue, resultQueue,timeout30, **kwargs):14 threadin…

編程統計BUF字單元數據中所含1的個數,并將結果存入COUNT單元中。

編程統計BUF字單元數據中所含1的個數&#xff0c;并將結果存入COUNT單元中。 代碼如下&#xff1a; DATA SEGMENT BUF DW 2345H ;隨機存儲一下數據 COUNT DB ? ;用于統計BUF字單元數據中所含1的個數 DATA ENDS STACK SEGMENT STACKDB 100 DUP(?);在堆棧段開辟一段大小為1…

循環鏈表(代碼、分析、匯編)

目錄&#xff1a;代碼&#xff1a;分析&#xff1a;匯編&#xff1a;代碼&#xff1a; CircleList.h #ifndef _CIRCLELIST_H_ #define _CIRCLELIST_H_typedef void CircleList;typedef struct _tag_CircleListNode CircleListNode;struct _tag_CircleListNode{CircleListNode…

Java Throwable setStackTrace()方法與示例

Throwable類setStackTrace()方法 (Throwable Class setStackTrace() method) setStackTrace() Method is available in java.lang package. setStackTrace()方法在java.lang包中可用。 setStackTrace() Method is used to sets stack trace elements that will be retrieved by…

IOS中設置全局變量

轉&#xff1a;http://blog.csdn.net/totogogo/article/details/7355203 有幾種方法 some developers recommend use singleton patter (ref link http://blog.csdn.net/kmyhy/article/details/7026511) 方法1&#xff1a;使用靜態變量 (不推薦&#xff09; 方法2&#xff1a; …

設計模式之Observer

觀察者模式可以參考郵件訂閱的例子 郵件訂閱設計到2個主要角色&#xff0c;一個是訂閱者(觀察者)&#xff0c;一個是發布者 發布者可以擁有一個觀察者的集合&#xff0c;可以添加&#xff0c;刪除觀察者&#xff0c;當發布者發布一個新的消息時&#xff0c;要郵件通知觀察者集合…

編寫一個程序,計算|X-Y|的值,并將結果存入RESULT單元中,其中X和Y都為帶符號字數據。

編寫一個程序&#xff0c;計算|X-Y|的值&#xff0c;并將結果存入RESULT單元中&#xff0c;其中X和Y都為帶符號字數據。 P154 例4.11 匯編思路:DATA段定義X、Y、RESULE分別用于存放隨機數、存放隨機數、存放最后計算結果。STACK段定義100DB大小的堆棧段運算存儲空間。將AX獲取…

java timezone_Java TimeZone inDaylightTime()方法及示例

java timezoneTimeZone類inDaylightTime()方法 (TimeZone Class inDaylightTime() method) inDaylightTime() method is available in java.util package. inDaylightTime()方法在java.util包中可用。 inDaylightTime() method is used to check whether the given date (d) is…