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

📄 zhanming.cpp

📁 采用了链表的形式
💻 CPP
字号:
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
struct station
{
char name[8];
struct station *nextSta;
};
struct station *creat_sta(struct station *h);
void print_sta(struct station *h);
int num=0;
main()
{
 struct station *head;
 head=NULL;
 printf("please input station name:\n");
 head=creat_sta(head);
 printf("------------------------\n");
 printf("Number of station = %d\n",num);
 print_sta(head);
 getch();
}
struct station *creat_sta(struct station *h)
{
   struct station *p1, *p2;
   p1=p2=(struct station *)malloc(sizeof(struct station));
   if(p2!=NULL)
   {
     scanf("%s",&p2->name);
	 p2->nextSta= NULL;
   }
   while(p2->name[0]!='#')
   {
      num++;
	  if(h==NULL)
		  h=p2;
	  else
		  p1->nextSta=p2;
	      p1=p2;
		  p2=(struct station *)malloc(sizeof(struct station));
		  if(p2!=NULL)
		  {
		     scanf("%s",&p2->name);
			 p2->nextSta=NULL;
		  }
   }
 return h;
}
void print_sta(struct station *h)
{
   struct station *temp;
   temp=h;
   while(temp!=NULL)
   {
           printf("%-8s",temp->name);
		   temp=temp->nextSta;
   }
}

⌨️ 快捷键说明

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