首页 > 代码库 > 嵌入式菜鸟算法③---链表操作

嵌入式菜鸟算法③---链表操作

主要内容:链表头插法和尾差法

#include <stdio.h>
#include <stdlib.h>//typedef int data;
typedef struct node
{
	char data;
	struct node* next;
}linklist;

/* method 1 insert node as first element */ 
linklist* CreateList1()
{
	char ch;
	linklist *head, *p, *q;
	int i = 1;
	head = NULL;
	
	printf("Please input single char:\n");
	scanf("\n%c", &ch);   // if not add \n before %c or add behind it will be some error,i'm not know it yet 
	
	while(ch != '#')
	{
		p = (linklist*)malloc(sizeof(linklist));
		p->data = http://www.mamicode.com/ch;>
输出结果:


嵌入式菜鸟算法③---链表操作