gpt4 book ai didi

c - 链接列表帮助,单链接(多个结构)(C 编程)

转载 作者:行者123 更新时间:2023-11-30 17:56:15 25 4
gpt4 key购买 nike

我需要一些有关链接列表的帮助。我已经弄清楚如何创建单独的链表,但是在尝试实现多个结构和列表时我遇到了困难。

我的上一个程序全部与结构一起使用,但现在我必须实现链接列表。它说在函数中使用“外部指针”来遍历各种列表。

这是我的一门课的作业,我不是要求你们都帮我做,而是要求帮助我指明正确的方向。

结构体如下:

            struct stockItem
{
char stockName[60];
char stockType[60];
int itemNumber;
float actualCost;
float markUp;
int totalCurrentInventory;
int monthlyRestock;
float price; //stores actual cost + markup

};


struct roomData
{
float widthFeet, widthInch;
float lengthFeet, lengthInch;
char roomName[100];
int roomNumberOfType;
char roomType[6]; //char of room type
int roomStock[100][2]; //for storing each room stock types
int roomHasStock; //if the room has a stock avaliable
int roomStockCount; //how many stocks the room has
float area; // sq ft
float rentalRate;
float profitsPerRoom;
float netProfit;
float grossProfit;
char stockLine[200];
};

struct staffData
{
char firstName[100];
char lastName[100];
char fullName[100];
int employeeNumber;
char typeOfEmployee[10];
char payType[10];
float hourlyWage;
float salary;
int hours;
char address[150];
char city[150];
char state[10];
int zip;
char phone[30];
float yearlyTotalPay;

struct hireDate //holds staff hire date
{
int month;
int day;
int year;
}hireDate;

struct birthDate //holds staff birth date
{
int month;
int day;
int year;
}birthDate;
};

最佳答案

typedef struct YourStructNode_ {

struct YourStructNode_ * next;
struct YourStructNode_ * prev;

YourStruct data;

} T_YourStructList;

将“YourStruct”替换为您的结构名称以创建双向链表。

即使您使用此模式多次创建 T_XXXX_List,您也应该使用相同的函数操作该列表,因为 T_Node 的前两个字段始终相同。

编写添加、插入、删除函数来操作该结构。

关于c - 链接列表帮助,单链接(多个结构)(C 编程),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13696967/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com