首页 > 解决方案 > 如何从链表中分配值

问题描述

我正在为我的这个愚蠢的任务添加下一点,现在我正在修改我的旧代码,因为我正在实现这些“链接列表”的东西,但我不知道你是如何从中提取数据的?

所以,软件需要为你在列表中的任何行星提取变量,并将数字分配给变量,如果这有意义的话?

typedef struct Planet
{
    char Planet_Name[30];
    double Fuel;
    double Velocity;
    double Height;
    double Gravity;
    int Maximum_Thrust;
    double Difficulty;
}Planet_t;

typedef struct PlanetNode
{
    Planet_t* planet_Name;
    struct PlanetNode* next;
}PlanetNode_t;

typedef struct PlanetList
{
    PlanetNode_t* head;
    int count;
}PlanetList_t;

(主要)

PlanetList_t* SolarSystem = calloc(1, sizeof(PlanetList_t));

printf("The Planets are (with their corresponding difficulty level) 
Pluto[0], Moon[1], Mercury[2], Mars[3].....

double height = SolarSystem->head->Height;
double velocity = SolarSystem[PlanetNum]->Velocity;
double fuel = SolarSystem[PlanetNum]->Fuel;
double gravity = SolarSystem[PlanetNum]->Gravity;
double fuelBurn;
double difficulty = SolarSystem[PlanetNum]->Difficulty;

所以基本上,我需要弄清楚最后一点。程序的每次迭代都会改变选定的行星(线性穿过行星),因此每次都需要更新变量。

标签: c

解决方案


推荐阅读