数据结构——头插法创建链表

来源:互联网 发布:松下程控交换机软件 编辑:程序博客网 时间:2024/05/29 05:11

头插法创建链表,刚开始学习数据结构与算法,还有很多不足,记录一下自己的学习历程。

#include<stdio.h>typedef struct link{char data;struct link *next;}linklist;/*头插法创建链表,并打印输出  可观察头插法输出刚好是逆序*/linklist *Create_List_Front(){linklist *head, *p;char ch;head = NULL;printf("依次输入字符('#'表示结束):\n");ch = getchar();while (ch != '#') {p = (linklist*)malloc(sizeof(linklist));p->data = ch;p->next = head;head = p;ch = getchar();}while (head != NULL) {printf("%c", head->data);head = head->next;}return head;}int main() {Create_List_Front();}
运行结果如下:

阅读全文
0 0