⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ll_fo.c

📁 cygwin下的包含各种c基本操作的demo程序
💻 C
字号:
//----------------------------------------------------------------//            the link_list operation function//----------------------------------------------------------------#include "my_common.h"int LinkListInit(link_list ** head){    if (!(*head = (link_list *)malloc(sizeof(link_list))))        return -1;    (*head)->data = NULL;    (*head)->next = NULL;         return 0; 		}int add_node(int data,int k,link_list * head){	 if ((head == NULL)||( k <=0))	 { return -1; }	 	 link_list *tmp_node = (link_list *)malloc(sizeof(link_list));	 tmp_node->data = data;	 tmp_node->next = NULL;	 	 if ((head->next == NULL)&&(k == 1))	 {	     head->next = tmp_node;	     //tmp->next = NULL;	     return 0;		 }	 	 while((k--)&&(head->next != NULL))	 { 	    head = head->next;    }      if (k>0)   { return -1;}      tmp_node->next = head->next;   head->next = tmp_node;   	 return 0;}int del_node(int n,link_list *head){    if ( n <= 0)    {  return -1; }        while(((n--) >= 1)&&(head->next != NULL))    {         head = head->next;                      }	    if (head->next == NULL)    {  return 0; }        head->next = ((link_list *)(head->next))->next; //NOTE:the force covert is important         return 0;	}void ll_print(link_list *head){   	  int ii = 0;	  	  printf("the value of the linklist is ");    while(head != NULL)    {         printf("node %d : %d   ",ii,head->data);	         head = head->next;    	   ii++;    }    printf("\n");    	}void ll_demo(void){    link_list * head = NULL;    int ii = 10;    int jj = 0;        LinkListInit(&head);        while( ii > 0)    {    add_node(ii,jj,head);    ii--,jj++;    }        add_node(999,3,head);    ll_print(head);        del_node(7,head);    ll_print(head);    	    return;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -