顺序表(代码、分析、汇编)

目录:

    • 代码:
    • 分析:
    • 汇编:

代码:

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.mzph.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…