當前位置:旅游攻略大全網 - 豪华酒店 - 求問c++裏面怎麽在鏈表裏再插入壹個鏈表,比如酒店為第壹個鏈表的壹個節點,然後每個房間是第二個鏈表

求問c++裏面怎麽在鏈表裏再插入壹個鏈表,比如酒店為第壹個鏈表的壹個節點,然後每個房間是第二個鏈表

#include?<iostream>

using?namespace?std;

struct?room{

int?romnum;

room?*next;

};

struct?hotel

{

char?name[50];

room*?pr;//指向room的指針

hotel*?ph;//指向下壹個hotel的指針。

};

void?initHotle(hotel*?&hp)

{

hp->ph=NULL;

hp->pr=NULL;

}

void?print(hotel*?&hp)

{

hotel*?temp=hp->ph;

if(temp==NULL)?cout<<"沒有酒店數據";

else{

while(temp){

cout<<temp->name;

temp=temp->ph;

}

}

}

void?findHotelRoomInfomation(char*?hname){

查鏈表,找到hname相匹配的,提出它的room頭指針,然後遍歷輸出唄。easy我就不填了。

自己搞。

}

int?main(){

hotel*?p=new?hotel();

initHotle(p);

print(p);

?

}

思路就是這樣,清晰不?關於鏈表數據的增刪查就不用我在添了吧?........再給妳畫個邏輯圖。

鏈表操作的話,自己慢慢填了啊............