头插法建立链表.txt

来自「数据结构用C实现」· 文本 代码 · 共 42 行

TXT
42
字号
///////////////////////////////////////////////
//			作者:03031A班  李戬			 //
//											 //
//		   2003年  xx月 xx日   晚			 //
///////////////////////////////////////////////
#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
typedef int datatype;
typedef struct node
{
	datatype data;
	struct node *next;
}linklist;
void jay(linklist *a)
{
	if(a->next!=NULL)
	{
		cout<<a->data<<endl;
		jay(a->next);
	}
}
void main()
{
	char ch;
	linklist *head,*s;
	head=NULL;
	cout<<"please enter a charter:"<<endl;
	cin>>ch;
	while(ch!='&')
	{
		s=(linklist *)malloc(sizeof(linklist));//建立新节点
		s->data=ch;//向新节点中添加内容
		s->next=head;//使新节点指向链首
		head=s;//改变头指针
		cout<<"please enter a charter:"<<endl;
		cin>>ch;
	}
	cout<<head->data<<endl;
	jay(s);
}

⌨️ 快捷键说明

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