栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

关于单链表的基本操作(c++)1创建2初始化3清空4求长5插入6遍历7尾插法8判空9查找10删除

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

关于单链表的基本操作(c++)1创建2初始化3清空4求长5插入6遍历7尾插法8判空9查找10删除

 本程序为完全个人理解所写。

因英语不好大部分用拼音代替。

#include
using namespace std;
typedef struct LNode{  //链表结构 
	int data;
	LNode *next;
}LNode,*linkList;

bool cj(linkList &L);
void qk(linkList &L);
void cd(linkList &L);
void cr(linkList &L,int i,int a);
void bl(linkList &L);
void wcf(linkList &L,int a);
void pk(linkList &L);
void cz(linkList &L,int a);
void sc(linkList &L,int a);
int main(){
	linkList L;
	int a,wz,z;
	for(int i=0;i<100;){
		cout<<"1初始化线性表 2清空线性表"<<"n";
		cout<<"3求线性表长度 4插入元素"<<"n";
		cout<<"5遍历线性表   6尾插法"<<"n";
		cout<<"7判空         8查找"<<"n";
		cout<<"9删除"<<"n";
		cin>>a;
		if(a==1)cj(L);
		if(a==2)qk(L);
		if(a==3)cd(L);
		if(a==4){
			cout<<"请输入插入的位置与值"<<"n";
			cin>>wz>>z;
			cr(L,wz,z);
		}
		if(a==5){
			bl(L);
		}
		if(a==6){
			cout<<"请输入长度"<<"n";
			cin>>z;
			wcf(L,z);
		}
		if(a==7){
			pk(L);
		}
		if(a==8){
			cout<<"请输入要查找的数"<<"n";
			cin>>z;
			cz(L,z);
		}
		if(a==9){
			cout<<"请输入要删除那个位置的数"<<"n";
			cin>>z;
			sc(L,z);
		}
	}
}

bool cj(linkList &L){//初始化线性?
	L=new LNode;
	L->next=NULL;
	return true;
}

void qk(linkList &L){//清空线性表
	L->next=NULL;
}

void cd(linkList &L){//求线性表长?
	linkList p;
	int a=0;
	p=L;
	while(p->next!=NULL){
		p=p->next;
		++a;
	}
	cout<<"长度为"next;
	}
	p->next=r->next;
	r->next=p;
}

void bl(linkList &L){//遍历线性表
	linkList p;
	p=L->next;
	while(p->next!=NULL){
		cout<data<<"n";
		p=p->next;
	}
	cout<data<<"n";
}

void wcf(linkList &L,int a){//尾插?
	linkList r,p;
	r=L;
	cout<<"输入数"<<"n";
	for(int i=0;i>p->data;
		p->next=NULL;
		r->next=p;
		r=p;
	}
}

void pk(linkList &L){//判?
	if(L->next==NULL){
		cout<<"为空"<<"n"; 
	}else{
		cout<<"不为空"<<"n";
	}
}

void cz(linkList &L,int a){//查?
	linkList p;
	int x=1;
	p=L->next;
	while(p->data!=a&&p->next!=NULL){
		p=p->next;
		++x;
	}
	if(p->next==NULL){
		cout<<"表中没有这个数"<<"n";
	}
	if(p->data==a){
		cout<<"表中的这个数在第"<next->next;
	r->next=p;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/396361.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号