实现一个应用程序:从终端接收不确定个数的字符串,并根据这些字符串建立链表
2013-03-18 15:50
363 查看
笔试题:
实现一个应用程序:从终端接收不确定个数的字符串,并根据这些字符串建立链表。假如应用程序链表已存在,则插入结点到链表;否则,新建立链表。
实现一个应用程序:从终端接收不确定个数的字符串,并根据这些字符串建立链表。假如应用程序链表已存在,则插入结点到链表;否则,新建立链表。
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct _node_t { char* name; struct _node_t* next; } Node; Node* create_list(const char* names[], int num) { Node* head = (Node*)malloc(sizeof(Node)); Node* p = head; Node* s; int i=1; head->name = 0; head->next= 0; for(i = 1; i < num; i++) { s = (Node*)malloc(sizeof(Node)); p->next = s; s->name = (char*)malloc(strlen(names[i])+1); strcpy(s->name, names[i]); s->next =0; p = s; } return head; } int Destroy_list( Node* head) { Node* Next; while( NULL != head ) { Next = head ->next; if ( NULL != head->next ) { printf("%s\n", head ->next->name); } head ->next = NULL; free( head ->name); free( head ); head = Next; } printf("succeed in deleting List.\n"); } int main(int argc, char **argv) { printf("Argument Count is %d.\n", argc); Node* head = create_list(argv, argc); Destroy_list(head); return 0; }
相关文章推荐
- 编程实现一个双向链表的建立
- 根据数组+链表的原理,自己实现一个简易版的HashMap
- 输入一组整型元素序列,使用尾插法建立一个带有头结点的单链表。 ② 实现该线性表的遍历。 ③ 在该单链表的第i个元素前插入一个整数。 ④ 删除该单链表中的第i个元素,其值通过参数将其返回。 ⑤ 建立两个
- 链表中每个结点的data域存放一个二进制位。并在此链表上实现对二进制数加1的运算。 用C语言编写 用以存放输入的二进制数 建立 一个带头结点的线性链表
- <仅是自己做笔记。。。系列15>实现一个挺高级的字符匹配算法: 给一串很长字符串,要求找到符合要求的字符串,例如目的串:123 1******3***2 ,12*****3这些都要找出来
- 根据链表的原理,自己实现一个简易版的LinkedList
- 实现一个挺高级的字符匹配算法: 给一串很长字符串,要求找到符合要求的字符串,例如目的串:123 1******3***2 ,12*****3 这些都要找出来
- C语言单向动态链表程序,实现链表的建立,合并,重新排序,链表元素的插入与删除,以及根据元素成员的值进行元素删除。
- 面向过程就是分析出解决问题所需要的步骤,然后用函数把这些步骤一步一步实现,使用的时候一个一个依次调用就可以了;面向对象是把构成问题事务分解成各个对象,建立对象的目的不是为了完成一个步骤,而是为了描叙某个事物在整个解决问题的步骤中的行为(转)
- 实现一个挺高级的字符匹配算法: 给一串很长字符串,要求找到符合要求的字符串,例如目的串:123 1******3***2 ,12*****3这些都要找出来
- 根据java的设计原则、设计模式实现了一个信息发送和接收的例子
- 6_8_2编写一个应用程序,该程序使用2个命令行参数,分别把值放在一个字符串和一个整形变量中,然后显示这些值
- 编写算法实现建立一个带头结点的含n个元素的双向循环链表H,并在链表H中的第i个位置插入一个元素e
- 实现一个挺高级的字符匹配算法: 给一串很长字符串,要求找到符合要求的字符串,例如目的串:123 1******3***2 ,12*****3 这些都要找出来
- 习题6:编写一个控制台应用程序,接收一个长度大于3的字符串
- 写一个控制台应用程序,它接收用户输入的字符串,将其中的字符顺序,反顺序输出!
- 实现一个命令行linux终端应用程序,把输入的指定文件,映射到内存中,并打印出文件内容
- (2)单链表的操作 ① 输入一组整型元素序列,使用尾插法建立一个带有头结点的单链表。 ② 实现该线性表的遍历。 ③ 在该单链表的第i个元素前插入一个整数。 ④ 删除该单链表中的第i个元素,其值通过参数
- 建立一个带附加头结点的单链表.实现测长/打印/删除结点/插入结点/逆置/查找中间节点/查找倒数第k个节点/判断是否有环
- 一个HTTP.二进制POST和HTTP指定长度接收的C++实现