⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hou_createlist.cpp

📁 VC++中 采用“尾插法”创建单链表的实现
💻 CPP
字号:
#include<stdio.h>
#include<malloc.h>
 

typedef struct node
{ int data;
  struct node *next;
} Linklist;


void hou_Createlist(Linklist *&head,int n)
{ int i;
  Linklist *p,*q;
  head=(Linklist *)malloc(sizeof(Linklist));
  head->next=NULL;
  q=head;
  for(i=0;i<n;i++)
  { p=(Linklist *)malloc(sizeof(Linklist));
    scanf("%d",&(p->data));
	  q->next=p;
	  q=p;
  }   
      q->next=NULL;
}


void print_list(Linklist *head)
{  Linklist *r;
   r=head->next;
   printf(" the result is: \n");
   while(r!=NULL)
   {  printf("%3d",r->data);
      r=r->next;
   }
      printf("\n");
}


void main()
{  Linklist *a;
   printf("hou_insert: \n");
   hou_Createlist(a,5);
   print_list(a);
   getchar();
}















⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -