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

3.6 链式存储结构(大话)c++实现 21.10.08

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

3.6 链式存储结构(大话)c++实现 21.10.08

#include "stdio.h"    
#include "string.h"
#include "ctype.h"      
#include "stdlib.h"  
#include"iostream"
#include"typeinfo"

#include "math.h"  
#include "time.h"
using namespace std;
#define OK 1
#define ERROR 0
#define TRUE 1
#define FALSE 0

#define MAXSIZE 20 

typedef int Status;
typedef int ElemType;


typedef struct node {
	
	ElemType shu;
	
	struct node* next;
}Node;


typedef struct node* linklist;


Status insert(linklist l, int index, ElemType e)
{
	linklist p,s;
	p = l;
	int j = 1;
	while (j < index && p)
	{
		p = p->next;
		++j;
	}
	if (j > index || !p)
	{
		cout << "失败了哦"<shu = e;
	s->next = p->next;
	p->next = s;
	cout << "添加成功了哦" << endl;
	return OK;



}


Status initlist(linklist l)
{
	linklist p;
	l->next = NULL;
	for (int i = 10; i > 0; i--)
	{
		p = (linklist)malloc(sizeof(Node));
		p->shu = i;
		p->next = l->next;
		l->next = p;

	}
	cout << "win";
	return OK;
}

Status del(linklist l, int index)
{
	linklist p,s;
	int j = 1;
	p = l;
	while (j < index&&p->next)
	{
		p = p->next;
		++j;
	}
	if (j > index || !p->next)
	{
		cout << "删除失败了哦" << endl;
		return FALSE;
	}
	s=p->next;
	p->next = s -> next;
	free(s);
	cout << "删除成功" << endl;
	return OK;

}

Status clearlist(linklist l)
{
	linklist p = l->next,s;
	while (p->next)
	{
		s= p->next;

		free(p);
		p = s;
	}

	return OK;

}

Status search(linklist l, int index)
{
	int j = 0;
	while (j < index&& l)
	{
		l = l->next;
		++j;
	}
	if (j > index || !l)
	{
		cout << "找不到哦"<shu<next;
		cout << s->shu <<" ";
		
	}
	
//	*ll = &l;
	insert(&l, 10, 99);
	s = &l;
	s = s->next;
	while (s)
	{
		cout << s->shu << " ";
		s = s->next;


	}
	del(&l, 2);
	s = &l;
	s = s->next;
	while (s)
	{
		cout << s->shu << " ";
		s = s->next;


	}
	search(&l, 9);
	//clearlist(&l);
	
	
}

 

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

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

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