现在的位置: 首页 > 综合 > 正文

链表

2013年10月13日 ⁄ 综合 ⁄ 共 582字 ⁄ 字号 评论关闭
#include<iostream.h>
#include<stdlib.h>
#define elemtype int
#define null 0
typedef struct lnode
{
 elemtype data;
 struct lnode *next ;
}lnode,*list;
void creatlist(list &l,int n)
{
 struct lnode *p;
 l=(list)malloc(sizeof(lnode));
 l->next=null;
 for(int i=n;i>0;i--)
 {
  p=(list)malloc(sizeof(lnode));
  int e;
   e=i;
      //cin>>e;
         p->data=e;
       p->next=l->next;
      l->next=p;
 }
}
 void shuchu(list l, int i)

 int e,j=0;
    struct lnode  *p;
 p=l;//->next;
   while( p && j<i)
   {
       j++;
       p=p->next;
    e=p->data;
    cout<<e<<" ";
   }
 }
void main()
{
 list obj;
 int i;
 i=5;
 creatlist(obj,i);
  shuchu(obj,i);
 cout<<endl;

抱歉!评论已关闭.