为什么我将链接重新定义为不同类型的符号"错误?

时间:2015-04-24 06:22:11

标签: c linked-list typedef

我将链接定义为struct STnode指针,但是我收到错误。此头文件中出现错误,这是唯一定义link的位置。这是整个headeer文件

 // Top-down red-black tree header file
 // These will have to change if data in node is more than just an int.
 typedef int Key;
 typedef Key Item;
 #define key(A) (A)
 #define less(A, B) (key(A) < key(B))
 #define eq(A, B) (key(A) == key(B))

 typedef struct STnode* link;

 struct STnode
 {
     Item item;  // Data for this node
     link l, r;  // left & right links
     char red;   // RB color
     int N;      // subtree size
 };

 extern Item NULLitem;

 void STinit();          // Initialize tree with just a sentinel

 Item STsearch(Key v);   // Find node for a key

 Item STselect(int k);   // Treat tree as flattened into an ordered array

 int STinvSelect(Key v); // Inverse of STselect

 void extendedTraceOn(); // Full tracing of intermediate trees

 void basicTraceOn();    // Just trace down and up passes for insert

 void traceOff();        // Run silent

 void STinsert(Item item);     // Insert an item.  No uniqueness check

 void verifyRBproperties();    // Ensure that tree isn't damaged

 void STprintTree();           // Dumps out tree

 void cleanUpUnbalanced(link h);  // Includes subtree sizes and verifies a               
 tree
 // built without balancing

每当我查找最初定义link的位置时,它会将我指向一个我甚至不在此代码中使用的头文件。感谢您提前获得所有帮助。

编辑:代码每次link更改为STlink

 // Top-down red-black tree header file
 // These will have to change if data in node is more than just an int.
 typedef int Key;
 typedef Key Item;
 #define key(A) (A)
 #define less(A, B) (key(A) < key(B))
 #define eq(A, B) (key(A) == key(B))

 typedef struct STnode* STlink; // Source

 struct STnode  // Error received - "redefinition of 'STnode' which directs me
                   to source above.
 {
     Item item;  // Data for this node
     STlink l, r;  // left & right links
     char red;   // RB color
     int N;      // subtree size
 };

 extern Item NULLitem;

 void STinit();          // Initialize tree with just a sentinel

 Item STsearch(Key v);   // Find node for a key

 Item STselect(int k);   // Treat tree as flattened into an ordered array

 int STinvSelect(Key v); // Inverse of STselect

 void extendedTraceOn(); // Full tracing of intermediate trees

 void basicTraceOn();    // Just trace down and up passes for insert

 void traceOff();        // Run silent

 void STinsert(Item item);     // Insert an item.  No uniqueness check

 void verifyRBproperties();    // Ensure that tree isn't damaged

 void STprintTree();           // Dumps out tree

 void cleanUpUnbalanced(STlink h);  // Includes subtree sizes and verifies a               
 tree
 // built without balancing

1 个答案:

答案 0 :(得分:0)

你说:

  

此头文件中出现错误,这是link定义的唯一位置。

不确定第一个link的定义位置,但您可以在代码部分使用STlink代替link来解决此问题。