创建链表
代碼#include?<iostream>
using?namespace?std;
struct?student??//定義結(jié)構(gòu)體
{
????int?data;
????student?*next;
};
//創(chuàng)建鏈表
student?*CreateList()
{
????student?*head=NULL;
????student?*p=new?student;
????cin>>p->data;????
????student?*end=p;
????while(p->data!=0)
????{
????????if(head==NULL)
????????????head=p;
????????else
????????????end->next=p;
????????end=p;
????????p=new?student;
????????cin>>p->data;
????}
????end->next=NULL;
????delete?p;
????return(head);
}
int?main()
{
????student?*Head?=?CreateList();
????student?*temp=Head;
????while(temp!=NULL)
????{
????????cout<<temp->data<<"?";
????????temp?=?temp->next;
????}
????return?1;????
}
using?namespace?std;
struct?student??//定義結(jié)構(gòu)體
{
????int?data;
????student?*next;
};
//創(chuàng)建鏈表
student?*CreateList()
{
????student?*head=NULL;
????student?*p=new?student;
????cin>>p->data;????
????student?*end=p;
????while(p->data!=0)
????{
????????if(head==NULL)
????????????head=p;
????????else
????????????end->next=p;
????????end=p;
????????p=new?student;
????????cin>>p->data;
????}
????end->next=NULL;
????delete?p;
????return(head);
}
int?main()
{
????student?*Head?=?CreateList();
????student?*temp=Head;
????while(temp!=NULL)
????{
????????cout<<temp->data<<"?";
????????temp?=?temp->next;
????}
????return?1;????
}
?
轉(zhuǎn)載于:https://www.cnblogs.com/ManMonth/archive/2010/06/23/1763951.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
- 上一篇: MySQL字符串拼接的两种方式
- 下一篇: CFLAGS详解