链表的一些常见笔试面试问题总结及代码.docVIP

  • 4
  • 0
  • 约5.18千字
  • 约 5页
  • 2018-05-22 发布于河南
  • 举报

链表的一些常见笔试面试问题总结及代码.doc

链表的一些常见笔试面试问题总结及代码

假设链表节点的数据结构为: struct node { int data; struct node* next; }; 创建单链表的程序为: struct node* create(unsigned int n) { //创建长度为n的单链表 assert(n 0); node* head; head = new node; head-next = NULL; cout 请输入head节点的值(int型):; cin head-data; if (n == 1) { ?? return head; } node* p = head; for (unsigned int i = 1; i n; i++) { ?? node* tmp = new node; ?? tmp-next = 0; ?? cout 请输入第 i+1 个节点的值(int):; ?? cin tmp-data; ?? p-next = tmp; ?? p = tmp; } return head; } 问题1:链表逆置 思想为:head指针不断后移,指针反向即可,代码为: void reverse(node* head) { if (head != NULL head-next != NULL) { 牋 node* p = head; 牋 node* q = head-next; 牋 p-n

文档评论(0)

1亿VIP精品文档

相关文档