Error[8]: Undefined offset: 924, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

文章目录

静态链表的基本 *** 作 静态链表的结构
typedef struct 
{
	char date;
	int next;
}*NodePtr,Node;
typedef struct 
{
	NodePtr node;
	int *used;//判断地址是否有值,1为有值,0为无值 
}*list,lnode;

静态链表的初始化
//静态链表的初始化
list initlist() 
{
	//temphead为指向整个静态链表的指针 
	list temphead=(list)malloc(sizeof(lnode)*initlen);
	//将静态链表的空间分配给node数组和used数组 
	temphead->node=(NodePtr)malloc(sizeof(Node)*initlen);
	temphead->used =(int*)malloc(sizeof(int)*initlen);
	//初始化头节点 
	temphead->node->date=';'=
	temphead->node->next-1;[
	temphead->used0]=1;//头节点不能用来存放数据 int
	; ifor
	(=i1;<i;initlen++i)[ 
	{
		temphead->used]i=0;}
	return
	; temphead}
void

打印静态链表
printlist ()list paraheadint 
{
	= p0;while
	(!=p-1)printf 
	{
		("%c",[parahead->node]p.)date ;=
		p[parahead->node]p.;next}
	printf
	("\n");}
void
在指定位置插入元素
insert (,list paraheadchar, chint) positionint 
{
	; iint
	= p0;//从头结点开始//找到插入位置前一个节点的下标 
	for
	(=i1;<i;position++i)=
	{
		p[parahead->node]p.;nextif
		(==p-1)printf
		{
			("插入位置%d大于当前链表的长度\n",)position;return
			;}
		}
	//查找当前链表中还有没有没有用到的空间
	int
	= q-1;for
	(=i1;<i;initlen++i)if 
	{
		([parahead->used]i==0)=
		{
			q;i[
			parahead->used]q=1;break
			;}
		}
	//如果没有空余的空间
	if
	(==q-1)printf 
	{
		("链表已满,不能插入元素\n");return
		;}
	[
	parahead->node]q.=date ;ch[
	parahead->node]q.=next[parahead->node]p.;next [
	parahead->node]p.=next;q}
void
删除指定位置的元素
deletenode1 (,list paraheadint) positionint 
{
	, i=p0;for
	(=i1;<i;position++i)=
	{
		p[parahead->node]p.;next if
		(==p-1)printf
		{
			("删除位置大于当前链表的实际长度\n");return
			;}
		}
	int
	= q[parahead->node]p.;next [
	parahead->node]p.=next [parahead->node]q.;next [
	parahead->used]q=0;}
void
删除指定位置的节点
deletenode2 (,list paraheadchar) chint 
{
	= p0;while
	([parahead->node]p.!=next -1&&[parahead->node[parahead->node]p.]next .!=date)ch=
	{
		p[parahead->node]p.;next }
	if
	([parahead->node]p.==next -1)printf
	{
		("链表中没有%c,无法删除\n",)ch;return
		;}
	int
	= q[parahead->node]p.;next [
	parahead->node]p.=next [parahead->node]q.;next [
	parahead->used]q=0;}
#
全部代码
include#
include#
defineinitlen 20 //静态链表的结构 
typedef
struct char 
{
	; dateint
	; next}
*,NodePtr;Nodetypedef
struct ; 
{
	NodePtr nodeint
	* ;used//判断地址是否有值,1为有值,0为无值 }
*,list;lnode//静态链表的初始化
initlist
list ()//temphead为指向整个静态链表的指针  
{
	=
	list temphead()listmalloc(sizeof()lnode*)initlen;//将静态链表的空间分配给node数组和used数组 
	=
	temphead->node()NodePtrmalloc(sizeof()Node*)initlen;=
	temphead->used (int*)malloc(sizeof(int)*)initlen;//初始化头节点 
	=
	temphead->node->date';'=-
	temphead->node->next1;[0
	temphead->used]=1;//头节点不能用来存放数据 int;
	for i(
	=1i;<;i++initlen)i[] 
	{
		temphead->used=i0;}return
	;
	} temphead//打印静态链表
void

printlist
( )intlist parahead= 
{
	0 p;while(
	!=-p1)printf( 
	{
		"%c",[]parahead->node.p);date =[
		p]parahead->node.p;}nextprintf
	(
	"\n");}//指定位置插入元素
void
insert
( ,charlist parahead,int ch)int position; 
{
	int i=
	0 p;//从头结点开始//找到插入位置前一个节点的下标 for
	(
	=1i;<;i++position)i=[
	{
		p]parahead->node.p;ifnext(
		==-p1)printf(
		{
			"插入位置%d大于当前链表的长度\n",);positionreturn;
			}}
		//查找当前链表中还有没有没有用到的空间
	int
	=
	- q1;for(
	=1i;<;i++initlen)iif( 
	{
		[]parahead->used==i0)=;
		{
			q[i]
			parahead->used=q1;break;
			}}
		//如果没有空余的空间
	if
	(
	==-q1)printf( 
	{
		"链表已满,不能插入元素\n");return;
		}[
	]
	parahead->node.q=;date [ch]
	parahead->node.q=[next]parahead->node.p;[next ]
	parahead->node.p=;next}q//删除指定位置的元素
void
deletenode1
( ,intlist parahead)int position, 
{
	= i0p;for(
	=1i;<;i++position)i=[
	{
		p]parahead->node.p;ifnext (
		==-p1)printf(
		{
			"删除位置大于当前链表的实际长度\n");return;
			}}
		int
	=
	[ q]parahead->node.p;[next ]
	parahead->node.p=[next ]parahead->node.q;[next ]
	parahead->used=q0;}//删除指定元素的节点
void
deletenode2
( ,charlist parahead)int ch= 
{
	0 p;while(
	[]parahead->node.p!=-next 1&&[[parahead->node]parahead->node.p].next !=)date=ch[
	{
		p]parahead->node.p;}next if
	(
	[]parahead->node.p==-next 1)printf(
	{
		"链表中没有%c,无法删除\n",);chreturn;
		}int
	=
	[ q]parahead->node.p;[next ]
	parahead->node.p=[next ]parahead->node.q;[next ]
	parahead->used=q0;}void
test
( )// Step 1. Initialize an empty list.=
{
	initlist
	list tempList ( );printlist(
	);tempList// Step 2. Add some characters.insert
 
	(
	,'H'tempList, 1) ;insert(
	,'e'tempList, 2) ;insert(
	,'l'tempList, 3) ;insert(
	,'l'tempList, 4) ;insert(
	,'o'tempList, 5) ;printlist(
	);tempList// Step 3. Delete some characters (the first occurrence).printf
 
	(
	"Deleting 'e'.\r\n");deletenode2(
	,'e'tempList) ;printf(
	"Deleting 'a'.\r\n");deletenode2(
	,'a'tempList) ;printf(
	"Deleting 'o'.\r\n");deletenode2(
	,'o'tempList) ;printlist(
	);tempListprintf(
	"删除第2个元素\r\n");deletenode1(
	,2tempList);printf(
	"删除第1个元素\r\n");deletenode1(
	,1tempList);printlist(
	);tempListinsert(
 
	,'x'tempList, 1) ;printlist(
	);tempList}int
main
( )test(
{
	);return0
	; }[+++]
[+++]

代码运行测试

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 925, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

文章目录

静态链表的基本 *** 作 静态链表的结构
typedef struct 
{
	char date;
	int next;
}*NodePtr,Node;
typedef struct 
{
	NodePtr node;
	int *used;//判断地址是否有值,1为有值,0为无值 
}*list,lnode;

静态链表的初始化
//静态链表的初始化
list initlist() 
{
	//temphead为指向整个静态链表的指针 
	list temphead=(list)malloc(sizeof(lnode)*initlen);
	//将静态链表的空间分配给node数组和used数组 
	temphead->node=(NodePtr)malloc(sizeof(Node)*initlen);
	temphead->used =(int*)malloc(sizeof(int)*initlen);
	//初始化头节点 
	temphead->node->date=';'=
	temphead->node->next-1;[
	temphead->used0]=1;//头节点不能用来存放数据 int
	; ifor
	(=i1;<i;initlen++i)[ 
	{
		temphead->used]i=0;}
	return
	; temphead}
void

打印静态链表
printlist ()list paraheadint 
{
	= p0;while
	(!=p-1)printf 
	{
		("%c",[parahead->node]p.)date ;=
		p[parahead->node]p.;next}
	printf
	("\n");}
void
在指定位置插入元素
insert (,list paraheadchar, chint) positionint 
{
	; iint
	= p0;//从头结点开始//找到插入位置前一个节点的下标 
	for
	(=i1;<i;position++i)=
	{
		p[parahead->node]p.;nextif
		(==p-1)printf
		{
			("插入位置%d大于当前链表的长度\n",)position;return
			;}
		}
	//查找当前链表中还有没有没有用到的空间
	int
	= q-1;for
	(=i1;<i;initlen++i)if 
	{
		([parahead->used]i==0)=
		{
			q;i[
			parahead->used]q=1;break
			;}
		}
	//如果没有空余的空间
	if
	(==q-1)printf 
	{
		("链表已满,不能插入元素\n");return
		;}
	[
	parahead->node]q.=date ;ch[
	parahead->node]q.=next[parahead->node]p.;next [
	parahead->node]p.=next;q}
void
删除指定位置的元素
deletenode1 (,list paraheadint) positionint 
{
	, i=p0;for
	(=i1;<i;position++i)=
	{
		p[parahead->node]p.;next if
		(==p-1)printf
		{
			("删除位置大于当前链表的实际长度\n");return
			;}
		}
	int
	= q[parahead->node]p.;next [
	parahead->node]p.=next [parahead->node]q.;next [
	parahead->used]q=0;}
void
删除指定位置的节点
deletenode2 (,list paraheadchar) chint 
{
	= p0;while
	([parahead->node]p.!=next -1&&[parahead->node[parahead->node]p.]next .!=date)ch=
	{
		p[parahead->node]p.;next }
	if
	([parahead->node]p.==next -1)printf
	{
		("链表中没有%c,无法删除\n",)ch;return
		;}
	int
	= q[parahead->node]p.;next [
	parahead->node]p.=next [parahead->node]q.;next [
	parahead->used]q=0;}
#
全部代码
include#
include#
defineinitlen 20 //静态链表的结构 
typedef
struct char 
{
	; dateint
	; next}
*,NodePtr;Nodetypedef
struct ; 
{
	NodePtr nodeint
	* ;used//判断地址是否有值,1为有值,0为无值 }
*,list;lnode//静态链表的初始化
initlist
list ()//temphead为指向整个静态链表的指针  
{
	=
	list temphead()listmalloc(sizeof()lnode*)initlen;//将静态链表的空间分配给node数组和used数组 
	=
	temphead->node()NodePtrmalloc(sizeof()Node*)initlen;=
	temphead->used (int*)malloc(sizeof(int)*)initlen;//初始化头节点 
	=
	temphead->node->date';'=-
	temphead->node->next1;[0
	temphead->used]=1;//头节点不能用来存放数据 int;
	for i(
	=1i;<;i++initlen)i[] 
	{
		temphead->used=i0;}return
	;
	} temphead//打印静态链表
void

printlist
( )intlist parahead= 
{
	0 p;while(
	!=-p1)printf( 
	{
		"%c",[]parahead->node.p);date =[
		p]parahead->node.p;}nextprintf
	(
	"\n");}//指定位置插入元素
void
insert
( ,charlist parahead,int ch)int position; 
{
	int i=
	0 p;//从头结点开始//找到插入位置前一个节点的下标 for
	(
	=1i;<;i++position)i=[
	{
		p]parahead->node.p;ifnext(
		==-p1)printf(
		{
			"插入位置%d大于当前链表的长度\n",);positionreturn;
			}}
		//查找当前链表中还有没有没有用到的空间
	int
	=
	- q1;for(
	=1i;<;i++initlen)iif( 
	{
		[]parahead->used==i0)=;
		{
			q[i]
			parahead->used=q1;break;
			}}
		//如果没有空余的空间
	if
	(
	==-q1)printf( 
	{
		"链表已满,不能插入元素\n");return;
		}[
	]
	parahead->node.q=;date [ch]
	parahead->node.q=[next]parahead->node.p;[next ]
	parahead->node.p=;next}q//删除指定位置的元素
void
deletenode1
( ,intlist parahead)int position, 
{
	= i0p;for(
	=1i;<;i++position)i=[
	{
		p]parahead->node.p;ifnext (
		==-p1)printf(
		{
			"删除位置大于当前链表的实际长度\n");return;
			}}
		int
	=
	[ q]parahead->node.p;[next ]
	parahead->node.p=[next ]parahead->node.q;[next ]
	parahead->used=q0;}//删除指定元素的节点
void
deletenode2
( ,charlist parahead)int ch= 
{
	0 p;while(
	[]parahead->node.p!=-next 1&&[[parahead->node]parahead->node.p].next !=)date=ch[
	{
		p]parahead->node.p;}next if
	(
	[]parahead->node.p==-next 1)printf(
	{
		"链表中没有%c,无法删除\n",);chreturn;
		}int
	=
	[ q]parahead->node.p;[next ]
	parahead->node.p=[next ]parahead->node.q;[next ]
	parahead->used=q0;}void
test
( )// Step 1. Initialize an empty list.=
{
	initlist
	list tempList ( );printlist(
	);tempList// Step 2. Add some characters.insert
 
	(
	,'H'tempList, 1) ;insert(
	,'e'tempList, 2) ;insert(
	,'l'tempList, 3) ;insert(
	,'l'tempList, 4) ;insert(
	,'o'tempList, 5) ;printlist(
	);tempList// Step 3. Delete some characters (the first occurrence).printf
 
	(
	"Deleting 'e'.\r\n");deletenode2(
	,'e'tempList) ;printf(
	"Deleting 'a'.\r\n");deletenode2(
	,'a'tempList) ;printf(
	"Deleting 'o'.\r\n");deletenode2(
	,'o'tempList) ;printlist(
	);tempListprintf(
	"删除第2个元素\r\n");deletenode1(
	,2tempList);printf(
	"删除第1个元素\r\n");deletenode1(
	,1tempList);printlist(
	);tempListinsert(
 
	,'x'tempList, 1) ;printlist(
	);tempList}int
main
( )test(
{
	);return0
	; }
[+++]

代码运行测试

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
C语言数据结构.静态链表_C_内存溢出

C语言数据结构.静态链表

C语言数据结构.静态链表,第1张

文章目录
  • 静态链表的基本 *** 作
    • 静态链表的结构
    • 静态链表的初始化
    • 打印静态链表
    • 在指定位置插入元素
    • 删除指定位置的元素
    • 删除指定位置的节点
  • 全部代码
  • 代码运行测试

静态链表的基本 *** 作 静态链表的结构
typedef struct 
{
	char date;
	int next;
}*NodePtr,Node;
typedef struct 
{
	NodePtr node;
	int *used;//判断地址是否有值,1为有值,0为无值 
}*list,lnode;

静态链表的初始化
//静态链表的初始化
list initlist() 
{
	//temphead为指向整个静态链表的指针 
	list temphead=(list)malloc(sizeof(lnode)*initlen);
	//将静态链表的空间分配给node数组和used数组 
	temphead->node=(NodePtr)malloc(sizeof(Node)*initlen);
	temphead->used =(int*)malloc(sizeof(int)*initlen);
	//初始化头节点 
	temphead->node->date=';'=
	temphead->node->next-1;[
	temphead->used0]=1;//头节点不能用来存放数据 int
	; ifor
	(=i1;<i;initlen++i)[ 
	{
		temphead->used]i=0;}
	return
	; temphead}
void

打印静态链表
printlist ()list paraheadint 
{
	= p0;while
	(!=p-1)printf 
	{
		("%c",[parahead->node]p.)date ;=
		p[parahead->node]p.;next}
	printf
	("\n");}
void
在指定位置插入元素
insert (,list paraheadchar, chint) positionint 
{
	; iint
	= p0;//从头结点开始//找到插入位置前一个节点的下标 
	for
	(=i1;<i;position++i)=
	{
		p[parahead->node]p.;nextif
		(==p-1)printf
		{
			("插入位置%d大于当前链表的长度\n",)position;return
			;}
		}
	//查找当前链表中还有没有没有用到的空间
	int
	= q-1;for
	(=i1;<i;initlen++i)if 
	{
		([parahead->used]i==0)=
		{
			q;i[
			parahead->used]q=1;break
			;}
		}
	//如果没有空余的空间
	if
	(==q-1)printf 
	{
		("链表已满,不能插入元素\n");return
		;}
	[
	parahead->node]q.=date ;ch[
	parahead->node]q.=next[parahead->node]p.;next [
	parahead->node]p.=next;q}
void
删除指定位置的元素
deletenode1 (,list paraheadint) positionint 
{
	, i=p0;for
	(=i1;<i;position++i)=
	{
		p[parahead->node]p.;next if
		(==p-1)printf
		{
			("删除位置大于当前链表的实际长度\n");return
			;}
		}
	int
	= q[parahead->node]p.;next [
	parahead->node]p.=next [parahead->node]q.;next [
	parahead->used]q=0;}
void
删除指定位置的节点
deletenode2 (,list paraheadchar) chint 
{
	= p0;while
	([parahead->node]p.!=next -1&&[parahead->node[parahead->node]p.]next .!=date)ch=
	{
		p[parahead->node]p.;next }
	if
	([parahead->node]p.==next -1)printf
	{
		("链表中没有%c,无法删除\n",)ch;return
		;}
	int
	= q[parahead->node]p.;next [
	parahead->node]p.=next [parahead->node]q.;next [
	parahead->used]q=0;}
#
全部代码
include#
include#
defineinitlen 20 //静态链表的结构 
typedef
struct char 
{
	; dateint
	; next}
*,NodePtr;Nodetypedef
struct ; 
{
	NodePtr nodeint
	* ;used//判断地址是否有值,1为有值,0为无值 }
*,list;lnode//静态链表的初始化
initlist
list ()//temphead为指向整个静态链表的指针  
{
	=
	list temphead()listmalloc(sizeof()lnode*)initlen;//将静态链表的空间分配给node数组和used数组 
	=
	temphead->node()NodePtrmalloc(sizeof()Node*)initlen;=
	temphead->used (int*)malloc(sizeof(int)*)initlen;//初始化头节点 
	=
	temphead->node->date';'=-
	temphead->node->next1;[0
	temphead->used]=1;//头节点不能用来存放数据 int;
	for i(
	=1i;<;i++initlen)i[] 
	{
		temphead->used=i0;}return
	;
	} temphead//打印静态链表
void

printlist
( )intlist parahead= 
{
	0 p;while(
	!=-p1)printf( 
	{
		"%c",[]parahead->node.p);date =[
		p]parahead->node.p;}nextprintf
	(
	"\n");}//指定位置插入元素
void
insert
( ,charlist parahead,int ch)int position; 
{
	int i=
	0 p;//从头结点开始//找到插入位置前一个节点的下标 for
	(
	=1i;<;i++position)i=[
	{
		p]parahead->node.p;ifnext(
		==-p1)printf(
		{
			"插入位置%d大于当前链表的长度\n",);positionreturn;
			}}
		//查找当前链表中还有没有没有用到的空间
	int
	=
	- q1;for(
	=1i;<;i++initlen)iif( 
	{
		[]parahead->used==i0)=;
		{
			q[i]
			parahead->used=q1;break;
			}}
		//如果没有空余的空间
	if
	(
	==-q1)printf( 
	{
		"链表已满,不能插入元素\n");return;
		}[
	]
	parahead->node.q=;date [ch]
	parahead->node.q=[next]parahead->node.p;[next ]
	parahead->node.p=;next}q//删除指定位置的元素
void
deletenode1
( ,intlist parahead)int position, 
{
	= i0p;for(
	=1i;<;i++position)i=[
	{
		p]parahead->node.p;ifnext (
		==-p1)printf(
		{
			"删除位置大于当前链表的实际长度\n");return;
			}}
		int
	=
	[ q]parahead->node.p;[next ]
	parahead->node.p=[next ]parahead->node.q;[next ]
	parahead->used=q0;}//删除指定元素的节点
void
deletenode2
( ,charlist parahead)int ch= 
{
	0 p;while(
	[]parahead->node.p!=-next 1&&[[parahead->node]parahead->node.p].next !=)date=ch[
	{
		p]parahead->node.p;}next if
	(
	[]parahead->node.p==-next 1)printf(
	{
		"链表中没有%c,无法删除\n",);chreturn;
		}int
	=
	[ q]parahead->node.p;[next ]
	parahead->node.p=[next ]parahead->node.q;[next ]
	parahead->used=q0;}void
test
( )// Step 1. Initialize an empty list.=
{
	initlist
	list tempList ( );printlist(
	);tempList// Step 2. Add some characters.insert
 
	(
	,'H'tempList, 1) ;insert(
	,'e'tempList, 2) ;insert(
	,'l'tempList, 3) ;insert(
	,'l'tempList, 4) ;insert(
	,'o'tempList, 5) ;printlist(
	);tempList// Step 3. Delete some characters (the first occurrence).printf
 
	(
	"Deleting 'e'.\r\n");deletenode2(
	,'e'tempList) ;printf(
	"Deleting 'a'.\r\n");deletenode2(
	,'a'tempList) ;printf(
	"Deleting 'o'.\r\n");deletenode2(
	,'o'tempList) ;printlist(
	);tempListprintf(
	"删除第2个元素\r\n");deletenode1(
	,2tempList);printf(
	"删除第1个元素\r\n");deletenode1(
	,1tempList);printlist(
	);tempListinsert(
 
	,'x'tempList, 1) ;printlist(
	);tempList}int
main
( )test(
{
	);return0
	; }


代码运行测试

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/867304.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-12
下一篇 2022-05-12

发表评论

登录后才能评论

评论列表(0条)

保存