关于单链表

#include <iostream>
#include <string>
using namespace std;

//int Er_fen(int A[],int length,int data)
//{
//	int begin=0;
//	int end=length-1;
//	while (begin<=end)
//	{
//		int midle=(begin+end)/2;
//		if (data==A[midle])
//			return midle;
//		else if(data>A[midle])
//			begin=midle+1;
//		else
//		    end=midle-1;
//		
//	}
//	return -1;
//}
//union 
//{
//	int i;
//	char x[2];
//
//}a;
//int fun_(int n)
//{
//	
//		if (n==0||n==1)
//		{
//			return 1;
//		}
//		else
//		{
//			return n*fun_(n-1);
//		}
//}
struct LinkNode
{
	int data;
	LinkNode* next;
};

void Print_(LinkNode* &head)
{ 
	LinkNode* p=head->next;
	while (p!=NULL)
	{
		cout<<p->data;
		p=p->next;
	}
}
LinkNode* Fanzhuan_(LinkNode* &head)
{
	if(head->next==NULL||head->next->next==NULL)
		return head;
	LinkNode* s=NULL;
	LinkNode* p=head->next;
	LinkNode* q=head->next->next;

	while (q)
	{
		s=q->next;
		q->next=p;
		p=q;
		q=s;
	}
	head->next->next=NULL;
	head->next=p;
	return head;
}
LinkNode* DeLe_(LinkNode* head,int i)
{
	if (head==NULL)
		return NULL;
	LinkNode* p=head->next;
	int count=1;
	while(p&&count!=i-1)
	{
		count++;
		p=p->next;
	}
	LinkNode* q=p->next;
	p->next=q->next;
	delete q;
	return head;

}
LinkNode* Insert(LinkNode* head,int i,int data)
{
	if (head->next==NULL)
	      return head;
	LinkNode* p=head->next;
	int count=1;
	while(p&&count!=i)
	{
		count++;
		p=p->next;
		
	}
	LinkNode* pNew=new LinkNode;
	pNew->data=data;
	pNew->next=p->next;
	p->next=pNew;
	return head;
}
int main()
{
	/*int A[8]={1,2,4,5,7,8,9,10};
	int i=0;

	int t=Er_fen(A,8,7);
	if (t==-1)
	{
	cout<<"没找到!";
	}
	else
	{
	cout<<"下标是"<<t<<endl;
	}
	cout<<++t+2;*/
	/*int m,n;
	cin>>n;
	m=fun_(n);
	cout<<m;
	return 1;*/
	LinkNode* head;
	head=new LinkNode;
	head->data=-1;
	head->next=NULL;
	LinkNode* p,*q;
	p=head;
	for (int i=0;i<10;++i)
	{
		q=new LinkNode;
		q->data=i;
		q->next=NULL;
		p->next=q;
		p=q;
	}
	head=Fanzhuan_(head);
	//head=Insert(head,5,6);
	head=DeLe_(head,5);
	Print_(head);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值