单链表的操作

#include<bits/stdc++.h>
using namespace std;
struct node{
	int data;
	struct node *next;
	struct node *prior;
};
struct node *head;
void extend(struct node *head,int value){
	struct node *p=head;
	while(p->next!=NULL){
		p=p->next;
	}
	cout<<"end"<<p->data<<endl;
	struct node *nn=new node;
	nn->data=value;
	nn->next=NULL;
	p->next=nn;
	cout<<"extend"<<p->next->data<<endl;
}
void insertfront(struct node *h,int value){
	struct node *t=new node;
	t->data=value;
	t->next=h;
	head =t;
}
bool find(struct node *h,int value){
	while(h!=NULL){
		if(h->data==value){
			return true;
		}
		h=h->next;
	}
	return false;
}
void deleteNode(struct node *h,int value){
	struct node *t=h;
	while(h->data!=value){
		t=h;
		h=h->next;
	}
	t->next=h->next;
}
void insertNode(struct node *h,int value,int insertValue){
	struct node * tt=new node;
	tt->data=insertValue;
	while(h->data!=value){
		h=h->next;
	}
	tt->next=h->next;
	h->next=tt;
}
void show(struct node *h){
	while(h!=NULL){
		cout<<h->data<<" ";
		h=h->next;
	}
	cout<<endl;
}
int main(int argc, char** argv) {
	freopen("abc.txt","r",stdin);
	int n;
	cin>>n;
	head=new node();
	head->next=NULL;
	struct node *p1;
	struct node *p2;
	for(int i=0;i<n;i++){
		if(i==0){
			int t;
			cin>>head->data;
			p1=head;
			p2=head;
		}else{
			p1=new node();
			cin>>p1->data;
			p1->next=NULL;
			p2->next=p1;
			p2=p1;
		}
	}
	//extend(head,12);
	//extend(head,13);
	//insertfront(head,3);
	//deleteNode(head,8);
	insertNode(head,2,99);
	show(head);
	int x=4;
	if(find(head,x)){
		cout<<x<<" find"<<endl;
	}else{
		cout<<x<<" not find"<<endl;
	}
	return 0;
}




 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值