在C++中,定义了结构体之后,怎么在函数中调用这些结构体?
我自己做了个 结构体的插入链表 你看看
#include<iostream>
using namespace std;
struct node
{
node *next;
int data;
};
class lianbiao:public node
{
public:
lianbiao()
{
head=new node[];
head->next=0;
head->data=0;
}
node *gethead()
{
return head;
}
void create_lianbiao(node *headnode);
void show(node *headnode);
void sethead(node *headnode)
{
head=headnode;
}
private:
node *head;
};
void lianbiao::create_lianbiao(node *headnode)
{
headnode=new node[];
headnode->data=0;
headnode->next=0;
sethead(headnode);
int dt;
cin>>dt;
while(dt!=2010)
{
node *hd=new node[];
hd->data=dt;
hd->next=NULL;
headnode->data=hd->data;
hd->next=headnode->next;
headnode->next=hd;
cin>>dt;
}
}
void lianbiao::show(node *headnode)
{
headnode=headnode->next;
while(headnode->next!=NULL)
{
cout<<headnode->data<<" ";
headnode=headnode->next;
}
cout<<headnode->data;
}
int main()
{
lianbiao lb;
lb.create_lianbiao(lb.gethead());
lb.show(lb.gethead());
return 0;
}
#include <cstdlib>
#include <iostream>
//定义结构体
struct point
{
//包含两个变量成员
int x;
int y;
};
using namespace std;
int main(int argc, char *argv[])
{
struct point pt;
pt.x=1;
pt.y=2;
cout<<pt.x<<endl<<pt.y<<endl;
return EXIT_SUCCESS;
}