2012-12-04 39 views
0

我需要一些帮助链表。 我已经想出了如何做单独的链表,但是我在试图实现多个结构和列表时遇到困难。链表的帮助,单链接(多结构)(C编程)

我最后的程序都使用对于结构,但现在我必须实现链表的。 它说在函数中使用“外部指针”来遍历各种列表。

这是功课我的课之一,我不要求你所有为我做到这一点,但我要求帮我指出了正确的方向。

的结构如下:

  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; 
      }; 
+2

您将需要更具描述性。 “多结构和列表”是什么意思?什么是“外部指针”?你应该只发布作业的实际文本。 (除非那会让你陷入困境) – xaxxon

+0

那么你在问如何在链表的节点中处理这些结构? –

回答

0
typedef struct YourStructNode_ { 

    struct YourStructNode_ * next; 
    struct YourStructNode_ * prev; 

    YourStruct data; 

} T_YourStructList; 

您的结构做一个双向链表的名称替换“YourStruct”。

即使你做一次T_XXXX_List多用这种方式,你应该用自T_Node的两个第一场相同功能的操作列表总是相同的。

写添加,插入,删除函数来处理这种结构。

0

是您的链表应该利用你已经开发的结构?这样你就有一个链表,其中每个节点都包含你列出的所有结构的一个实例。

struct node { 
    struct node *left; 
    struct node *right; 
    roomData room; 
    stockItem stock; 
    staffData staff; 
    hireDate hire; 
    birthDate birth; 
};