1、尾插法创建单链表

 

void CreateList(List &L,int n)
{
    L=new LNode;
    L->next=NULL;
    r=L;
    for(i=0;i<n;++i)
   {
      p=new LNode;
      cin>>p->data;
      p->next=NULL;
      r->next=p;
      r=p;
   }
}

2、前插法创建单链表

void CreatList(List &L,int n)
{
    L=new LNode;
    L->next=NULL;
    for(int i=0;i<n;i++)
   {
      p=new LNode;
      cin>>p->data;
      p->next=L->next;
      L->next=p;  
   } 
}

相关文章:

  • 2022-12-23
  • 2021-07-05
  • 2021-07-09
  • 2021-10-25
  • 2021-12-19
  • 2021-09-08
  • 2022-12-23
  • 2021-08-10
猜你喜欢
  • 2022-12-23
  • 2021-06-11
  • 2022-12-23
  • 2021-06-07
  • 2021-04-06
  • 2022-12-23
相关资源
相似解决方案