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

📄 新建 文本文档.txt

📁 简单的链表实现 链表可以初步了解
💻 TXT
字号:
#include <stdio.h> 
#include <string.h> 
#include <malloc.h> 

typedef struct _ChNode 
{ 
int ch; 
struct _ChNode *next; 
} ChNode; 

ChNode* cncreate(const char *str) 
{ 
ChNode *head = NULL, *tail, *node; 

while (*str) 
{ 
node = (ChNode *)malloc(sizeof(ChNode)); 
node->ch = *str; 
node->next = NULL; 
if (head == NULL) 
{ 
head = node; 
tail = node; 
} 
tail->next = node; 
tail = node; 
str++; 
} 
return head; 
} 

ChNode* cnchr(ChNode *node, int ch) 
{ 
while (node) 
{ 
if (node->ch == ch) 
{ 
return node; 
} 
node = node->next; 
} 
return NULL; 
} 

ChNode* cntail(ChNode *node) 
{ 
while (node->next) 
{ 
node = node->next; 
} 
return node; 
} 

void cnins(ChNode *a, ChNode *b) 
{ 
ChNode *btail = cntail(b); 
btail->next = a->next; 
a->next = b; 
} 

void cncat(ChNode *a, ChNode *b, int ch) 
{ 
ChNode *node = cnchr(a, ch); 
if (node == NULL) 
{ 
node = cntail(a); 
} 
cnins(node, b); 
} 

void cnprint(ChNode *node) 
{ 
while (node) 
{ 
printf("%c", node->ch); 
node = node->next; 
} 
printf("\n"); 
} 

void main() 
{ 
ChNode *list1, *list2; 

list1 = cncreate("show me the money!"); 
cnprint(list1); 
list2 = cncreate("give me five!"); 
cnprint(list2); 
cncat(list1, list2, 'w'); 
cnprint(list1); 
}

⌨️ 快捷键说明

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