int main(void)
{
int i, j, num[6] = {1, 2, 3, 4, 5, 6}, cot = 0
for(i = 0 cot <巧吵 4)
{
int index = num[i]
for(j = i )
{
printf("%d"蔽宽键, num[j])
j++
if(j == 6) j = 0
if(index == num[j]) break
}
puts("")
i--
if(i == -1) i = 宏巧5
cot++
}
return 0
}
#include <stdio.h>#include <string.h>
#include <malloc.h>
struct my_list
{
struct my_list * next
int num
}
// 创弯喊建表
struct my_list * create_list()
{
struct my_list * list = (struct my_list*)malloc(sizeof(struct my_list))
list->next = 0
return list
}
// 在尾部插入
void push_list(struct my_list * head, int num)
{
while(head->next != 0) head = head->next
head->next = create_list()
head->next->num = num
}
// 读取第n个元素
int get_list(struct my_list * head, int where)
{
for(int i = 0i <where++i)
head = head->next
return head->next->num
}
// 删除表
void destroy_list(struct my_list * list)
{
if(list->埋悉野next) destroy_list(list->next)
free(list)
}
// 移除第where个元陆物素
void remove_list(struct my_list * head, int where)
{
for(int i = 0i <where++i)
{
head = head->next
}
struct my_list * dest = head->next
head->next = head->next->next
dest->next = 0
destroy_list(dest)
}
int main()
{
struct my_list * li = create_list()
// 插入12,13,14
push_list(li, 12)
push_list(li, 13)
push_list(li, 14)
printf("before remove 0 :%d %d\n", get_list(li, 0), get_list(li, 1))
// 移除0位置元素
remove_list(li, 0)
printf("after remove 0: %d %d\n", get_list(li, 0), get_list(li, 1))
destroy_list(li)
return 0
}
++qq群:193406976
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)