C语言指针实现链表以及用gcc编译输出
C语言指针实现链表以及用gcc编译输出
代码写的链表实现创建,插入,删除的操作,很基础的一些动作。
可以本地用NotePad写好代码,然后通过Filezilla上传到服务器上去。
通过Xshell进入目录,gcc test.c -o test完成命令的编译。
或者写个MakeFile也可以。
如下是源码:
#include
#include
typedef int datatype;
#define ERROR -1;
#define TRUE 1;
typedef struct link_node
{
datatype data;
struct link_node *next;
}link_node;
//creat a node
link_node *function_create_linklist(link_node *head, datatype *p_data)
{
link_node *p, *q, *start;
//init
if((head == NULL) & (NULL != p_data))
{
head = (link_node *)malloc(sizeof(link_node));
printf("*p_data [%d]\n", *p_data);
head->data = *p_data++;
head->next = NULL;
}
//start = head;
p = head;
q = head;
/*
if('\0' == *p_data)
{
printf("error data empty\n");
return NULL;
}*/
while('\0' != *p_data)
{
p = (link_node *)malloc(sizeof(link_node));
p->data = *p_data++;
p->next = NULL;
printf("p->data [%d] [%d]\n", p->data, *p_data);
q->next = p;
q = p;
}
printf("function_create_linklist DONE\n");
return head;
};
//insert a node
int function_insert_node(link_node *head, int index, datatype data)
{
link_node *p, *q;
p = head;
q = NULL;
int i=0;
for(i=0; i
{
printf("i:[%d]\n",i);
p = p->next;
}
q = (link_node *)malloc(sizeof(link_node));
q->data = data;
q->next = p->next;
p->next = q;
return TRUE;
}
//delete a node
int function_del_node(link_node *head, int index)
{
link_node *p, *q;
p = head;
q = head;
int i = 0;
for(i=0; i
{
q = p;
p = p->next;
}
q->next = p->next;
free(p);
p = NULL;
return TRUE;
}
//output
int output_data(link_node *head)
{
link_node *p;
p = head;
printf("output_data enter\n");
while(p != NULL)
{
printf("data:%d\n",p->data);
p = p->next;
}
printf("output_data enter exit\n");
}
main()
{
printf("my test ++++++++++ 20200607 ++++++++++\n");
#if 1 //char test
//char *str = "who are you";
char str[] = "who are you";
int length = strlen(str);
printf("len[%d] size[%d]\n", length, sizeof(str));
#endif
#if 0 //linklist test
link_node *p_head;
//head.data = 999,
//head.next = NULL;
p_head = NULL;
datatype data[] = {1,2,3,4,5,6,7,9,10,11,12,13,'\0'};
p_head = function_create_linklist(p_head, data);
//create a node
output_data(p_head);
function_insert_node(p_head, 3, 100);
output_data(p_head);
function_del_node(p_head, 3);
output_data(p_head);
#endif
#if 0// sorting alg
//int data[] = {6,3,6,8,9,11,100,17,99};
int length = sizeof(data)/sizeof(int);
printf("\n\n\n sorting start ######################### \n \n data length[%d] \n", length);
int i, j;
printf("start data:");
for(i=0; i
{
printf("[%d]", data[i]);
}
printf("\n");
for(i=0; i
{
printf("BIG i - [%d]\n", i);
for(j=0; j
{
printf("j - [%d]\n", j);
if(data[j+1] < data[j])
{
int temp = data[j];
data[j] = data[j+1];
data[j+1] = temp;
printf("swap data_j[%d] data_j+1[%d]\n", data[j], data[j+1]);
}
}
}
printf("after data:");
for(i=0; i
{
printf("[%d]", data[i]);
}
printf("\n");
return;
#endif
}
C语言指针实现链表以及用gcc编译输出相关教程
java实现arcgis地图分屏(双图)
java实现arcgis地图分屏(双图) 本博文采用Java语言,利用arcgis api for javascript 4.16地图服务,实现地图分屏,直接上源码: !DOCTYPE htmlhtml lang=enhead meta charset=UTF-8 title视图对比/title style html,body{ width: 100%; height: 100%; paddi
进程间通信——基于共享内存和信号量实现共享队列
进程间通信——基于共享内存和信号量实现共享队列 一、进程间的通信方式 进程间通信就是在不同进程之间传播或交换信息,通信方式一般分为管道、命名管道(FIFO)、消息队列、信号量(Semaphore)、共享内存(Shared Memory)五种。 管道:只能用于父子进程或
springboot+Hystrix+eureka+Openfeign实现分布式生产者消费者直
springboot+Hystrix+eureka+Openfeign实现分布式生产者消费者直接的调用以及解决服务降级、服务熔断、服务限流等问题(1) springboot+Hystrix+eureka+Openfeign实现分布式生产者消费者直接的调用以及解决服务降级、服务熔断、服务限流等问题(1) Hystrix是什么
PAT甲级1099 Build A Binary Search Tree (30分)|C++实现
PAT甲级1099 Build A Binary Search Tree (30分)|C++实现 一、题目描述 原题链接 For each test case, print in one line the level order traversal sequence of that tree. All the numbers must be separated by a space, with no extra space at the end
【React】实现div高度适配浏览器窗口大小
【React】实现div高度适配浏览器窗口大小 实现的方法有好几种,本人仅提供自己在实现过程中使用的这一种。 div style={{height:100%,position:absolute,width:100%,left:0,top:0}} {/* 中间内容省略 */}/div 实现效果:
Laravel实现权限控制
Laravel实现权限控制 文章目录 一、RBAC 二、认证授权逻辑 三、具体实现 创建表的迁移文件 用户: 角色: 权限: 创建控制器 修改路由文件 路由别名 拓展FormRequest验证 中间件过滤 控制器方法 RBAC: role base access control 基于角色的用户访问权限控制权
基于心电信号的身份识别(1)心电数据库读取和操作(Python实现
基于心电信号的身份识别(1)心电数据库读取和操作(Python实现) 阅读本节之前,需要阅读如下文献,补充相应基础知识。 宋喜国,邓亲恺.MIT-BIH心率失常数据库的识读及应用[J].中国医学物理学杂志,2004(04):230-232. 心电数据库的读取和操作,以ECG ID Databa
手把手教学,实现两层神经网络(在b站有辅助视频,视频非原创)
手把手教学,实现两层神经网络(在b站有辅助视频,视频非原创) 如何实现两层神经网络 三军未动,粮草先行(使用的软件和工具) 热身:用numpy实现两层神经网络 有关反向传播的矩阵乘法推导 PyTorch:Tensors来创建网络,计算损失以及反向传播 我们可以看出来自动