HQYJ 2024-2-21 作业

  1. 复习课上内容(已完成)
  2. 结构体字节对齐,64位没做完的做完,32位重新都做一遍,课上指定2字节对齐的做一遍,自己验证(已完成)
  3. 两种验证大小端对齐的代码写一遍
  4. 复习指针内容(已完成)
  5. 完善顺序表已写出的功能

3.两种验证大小端对齐的代码写一遍

cs 复制代码
//验证大小端存储
#include <stdio.h>
#include <string.h>
int main(int argc, const char *argv[])
{
	int a = 0x12345678;
	char *p = &a;
	if(*p = 0x78)
	{
		printf("小端存储\n");
	}
	else
	{
		printf("大端存储\n");
	}
	return 0;
}
cs 复制代码
#include <stdio.h>
#include <string.h>
union A
{
	char t1;
	int t2;
};
int main(int argc, const char *argv[])
{
	union A a1;
	a1.t2 = 0x12345678;
	if(a1.t1==0x78)
	{
		printf("小端\n");
	}
	else
	{
		printf("大端\n");
	}
	
	return 0;
}

5.完善顺序表已写出的功能

seq.list.h文件

cs 复制代码
#ifndef __SEQ_LIST_H__
#define __SEQ_LIST_H__
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#define MAX 7
typedef int datatype;
typedef struct seq_list
{
	datatype data[MAX];
	int len;
}seq_list,*seq_p;



seq_p creat_seq_list();
int seq_empty(seq_p L);
int seq_full(seq_p L);





#endif

seq.list.c文件

cs 复制代码
#include "seq_list.h"
seq_p creat_seq_list()
{
	seq_p L = (seq_p)malloc(sizeof(seq_list));
	if(L==NULL)
	{
		printf("申请空间失效\n");
		return NULL;
	}
	L->len = 0;//长度置0
	bzero(L,sizeof(L->data));
	return L;
}

//判空
int seq_empty(seq_p L)
{
	if(L==NULL)
	{
		return -1;
	}
	return L->len==0?1:0;
}

//判满
int seq_full(seq_p L)
{
	if(L==NULL)
	{
		return -1;
	}
	return L->len==MAX?1:0;
}

main.c 文件

cs 复制代码
#include "seq_list.h"
int main(int argc, const char *argv[])
{
	seq_p L = creat_seq_list();
	printf("%d\n",seq_empty(L));
	printf("%d\n",seq_full(L));

	return 0;
}
相关推荐
脱氧核糖核酸__2 分钟前
LeetCode热题100——189.轮转数组(题解+答案+要点)
数据结构·c++·算法·leetcode
贾斯汀玛尔斯21 分钟前
每天学一个算法-快速排序(Quick Sort)
数据结构·算法
炽烈小老头22 分钟前
【每天学习一点算法 2026/04/16】逆波兰表达式求值
学习·算法
优家数科34 分钟前
水质监测不准?解密云端 TDS 数据建模纠偏算法
算法
木井巳40 分钟前
【递归算法】组合总和
java·算法·leetcode·决策树·深度优先·剪枝
coding者在努力1 小时前
被n整除的n位数
c++·算法
黎阳之光1 小时前
去标签化无感定位技术突破,黎阳之光重构空间定位技术路径
大数据·人工智能·算法·安全·数字孪生
见叶之秋1 小时前
【数据结构】详解二叉树和堆
数据结构·算法
CoovallyAIHub2 小时前
MSD-DETR:面向机车弹簧检测的可变形注意力Detection Transformer
算法·架构
CoovallyAIHub2 小时前
不改权重、不用训练!BEM用背景记忆抑制固定摄像头误检,YOLO/RT-DETR全系有效
算法·架构·github