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",