Chinaunix首页 | 论坛 | 博客
  • 博客访问: 544636
  • 博文数量: 252
  • 博客积分: 1068
  • 博客等级: 少尉
  • 技术积分: 1775
  • 用 户 组: 普通用户
  • 注册时间: 2012-05-05 21:33
文章分类

全部博文(252)

文章存档

2013年(21)

2012年(231)

分类:

2012-06-04 14:40:22

原文地址:单链表的建立 作者:kevin33643

#include
using namespace std;
 
typedef struct node
{
    int data;
    struct node *next;
}Node;
 
Node *CreateList()
{
    int i=0;//member's count
    Node *head,*p,*q;
    int temp;
    head=new Node;//creat node:head
 
    while(1)
    {
        cout<<"Please input the data:"<        cin>>temp;
  
        if(temp=0)//if temp=0 then quit while
            break;
  
        p=new Node;
        p->data=temp;
  
        if(++i=1)//only node:head exist
            head->next=p;
        else
            q->next=p;
        q=p;
    }
    q->next=NULL;//end of link
    return head;
}
 
int main(void)
{
    CreateList();
    return 0;
}
阅读(301) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~