myhead.h

来自「数据结构基本」· C头文件 代码 · 共 54 行

H
54
字号
#include<iostream.h>

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


node *create(int *i,int n)
{
	node *head=NULL,*p;
	while(n-->0)
	{
		p=new node;
		p->data=*i++;
		p->next=head;
		head=p;
	}
	return head;
}      
//以上建立一个单链表

node *copy(node *r)
{
	node *p,*m,*head=NULL,*temp;   //设置临时指针变量 
	while(r)
	{
		m=new node;
		m->data=r->data;
		p=head;               //将开始结点变成终端结点
		while(p && p->data<m->data)
		{                   //每次循环将后一个结点变成开始结点
			temp=p;
			p=p->next;
		}
		if(p==head)
			head=m;
		else
			temp->next=m;
		m->next=p;
		r=r->next;
	}
	return head;//如是空表或单结点表,直接返回head 

}       
//以上对原链表进行逆置

void show(node *p)
{
	while(p)
		cout<<p->data<<" ",p=p->next;   //输出结果
	cout<<endl;
}

⌨️ 快捷键说明

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