0

我正在尝试从另一个节点访问一个节点的数据。

struct orderNode 
{
  int price;
  int quantity;
};

struct lnode
{
  struct lnode* data;
  struct lnode* next;
  struct lnode* prev;
};

我如何使用 lnode 值(数据)来访问值(价格和数量)。

4

2 回答 2

3
struct orderNode 
{
   int price;
   int quantity;
};

struct lnode
{ 
  struct lnode* next;
  struct lnode* prev;
  struct orderNode* oNode;
};
于 2013-03-09T01:10:19.280 回答
1

If you want lnode.data to access an orderNode your definition is wrong, it'd have to be:

struct lnode
{
   struct orderNode *data;
   ...

You can then use lnode.data->price or lnode.data->quantity, assuming you've assigned the data pointer to a valid orderNode struct.

于 2013-03-09T01:17:57.427 回答