C语言实现复数数据结构


19m094

复数数据结构

头文件

#ifndef _COMPLEX_H_
#define _COMPLEX_H_

typedef struct complex
{
   
	double Realpart;
	double Imagepart;
} Complex;//复数结构

typedef struct node
{
   
	Complex complex;
	struct node* next;
} Node;//节点

typedef struct linklist
{
   
	Node* front;	//头指针
	int items;		//节点数量
} Linklist;//头节点

/*操作:	初始化链表								*/
/*前提:	pL指向一个链表							*/
/*后件:	链表初始化为空                          */
void InitializeList(Linklist* pL);

/*操作: 将复数节点插入指定位置						*/
/*前提: pL指向一个复数链表,i为插入位置			*/
/*后件: 复数节点插入链表							*/
void InsertNode(Linklist* pL, int i);

/*操作:	获取指定位置的复数						*/
/*前提:	pL指向一个链表,i为指定位置				*/
/*后件:	返回一个复数		                    */
Complex GetComplex(Linklist* pL, int i);

/*操作:	获取两个复数并计算和					*/
/*前提:	复数链表存在且不为空					*/
/*后件:	返回计算结果		                    */
Complex Sum(Linklist* pL, int index1, int index2);

/*操作:	获取两个复数并计算差					*/
/*前提:	复数链表存在且不为空					*/
/*后件:	返回计算结果		                    */
Complex Difference(Linklist* pL, int index1, int index2);

/*操作:	获取两个复数并计算积					*/
/*前提:	复数链表存在且不为空					*/
/*后件:	返回计算结果		                    */
Complex Multiply(Linklist* pL, int index1, int index2);

/*操作:	将指定位置的复数节点删除				*/
/*前提:	pL指向一个复数链表						*/
/*后件:	复数节点被删除			                */
void DeleteNode(Linklist* pL, int i);

/*操作:	将指定位置的复数修改					*/
/*前提:	pL指向一个复数链表						*/
/*后件:	复数被修改				                */
void ChangeComplex(Linklist* pL, int i);

/*操作:	遍历链表打印节点中复数					*/
/*前提:	pL指向一个复数链表						*/
/*后件:	打印已有复数			                */
void Print(Linklist* pL);

/*操作:	将链表内存释放							*/
/*前提:	pL指向一个复数链表						*/
/*后件:	成为空表				                */
void DestroyList(Linklist* pL);

/*操作:	获取复数实部							*/
/*前提:	传入一个复数							*/
/*后件:	返回实部			                    */
double Getreal(Complex c);

/*操作:	获取复数虚部							*/
/*前提:	传入一个复数							*/
/*后件:	返回虚部			                    */
double Getimage(Complex c);
#endif // !_COMPLEX_H_

函数文件

#include <stdio.h> 
#include <stdlib.h> 
#include "complex.h"

void InitializeList(Linklist* pL)
{
   
	pL->front = NULL;
	pL->items = 0;
}

void InsertNode(Linklist* pL, int i)
{
   
	Node* pN, * pC;
	if (!pL->front)
	{
   //空表
		pL->front = (Node*)malloc(sizeof(Node));
		pL->items++;
		printf(" Realpart: ");
		scanf("%lf", 
  • 1
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值