计蒜客 数据结构 链表 ——应用筛选简历 C++
来源:互联网 发布:g3110扫描仪软件 编辑:程序博客网 时间:2024/06/15 04:50
//这个程序是,没有头节点的//2016/08/10#include<iostream>using namespace std;class Node {public: int data; Node* next; Node(int _data) { data = _data; next = NULL; }};class LinkList {private: Node* head;public: LinkList() { head = NULL; } //插入函数 void insert(Node *node, int index) { //插入的时候先检查是否是有这样的头节点,若是没有头结点的话建立一个头结点 if (head == NULL) { head = node; // head->next = head; return; } //检查插入的位置,若是头部插入节点。若是插入的位置是0的话,头结点不是数据元素的结点(⊙o⊙)哦!! if (index == 0) { //node->next = head->next; // head->next = node; //还是使用循环链表,没有头节点 node->next = head; head = node; return; } //Node *current_node = head->next; Node* current_node = head; int count = 0; //寻找插入位置 while (current_node->next != head && count < index - 1) { current_node = current_node->next; count++; } //讲节点插入,node指向插入节点 if (count == index - 1) { node->next = current_node->next; current_node->next = node; }// if (node == head->next) {// head = node;// } } //删除函数 void delete_node(int index){ //删除之前要检查头节点是否为空 if(head == NULL){ return; } Node* current_node = head; int count = 0; //检查删除位置,删除头节点的情况下,这个是没有头节点的情况 if(index == 0){ head = head->next; delete current_node; return; } //找到删除的前一个位置 while(current_node->next != NULL && count < index -1){ current_node = current_node->next; count++; } //删除节点current_node指向删除节点的前一个位置,delete_node是指向删除节点 if(count == index - 1 && current_node->next != NULL){ Node* delete_node = current_node->next; current_node->next = delete_node->next; //用完的空间记得回收 delete delete_node; } } //链表长度函数 int get_length(Node* head){ int count = 0; Node* p = head->next; while(p){ count = count +1; p = p->next; } return count; } //输出函数 void output_node(){ int len = get_length(head); int count = -1; if(head == NULL){ return ; } Node* current_node = head; while(current_node != NULL){ count = count + 1; if(count == len/2){ //去掉结尾的换行符,就因为换行符就判断为错,计蒜客这点很不好。 cout<< current_node->data; } current_node = current_node->next; } }};int main() { int n,m,num_id; LinkList linklist; cin >> n >> m ; for(int i = 1; i <= n ;i++){ Node* node = new Node(i); linklist.insert( node ,i - 1); } for(int j = 1 ; j <= m ;j++){ //这道题目是输入特殊不喜欢的数字就删除对应的序号的简历 //输入一个就删除一个 cin>>num_id; linklist.delete_node(num_id - 1); } linklist.output_node(); return 0;}
0 0
- 计蒜客 数据结构 链表 ——应用筛选简历 C++
- 筛选简历
- 阿里巴巴简历筛选原则
- 阿里HR筛选简历
- 简历筛选标准
- 阿里HR筛选简历
- 阿里校招内推简历筛选的筛选标准
- 阿里HR筛选简历标准
- 阿里巴巴校招内推简历筛选方案
- C-数据结构-图-应用
- C++ 数据结构应用——链表
- 素数筛选——爱拉托逊斯筛选法
- HR筛选简历的12个要点,投简历必读!
- 投简历必读:HR筛选简历的12个要点!
- 公司是如何筛选简历的
- 我是这样在第一轮筛选简历的
- 我们公司怎么筛选简历的
- 一个外企HR自述如何筛选简历
- HTML5创建的简易web表单
- HDU 2604 Queuing [递推]【矩阵快速幂】
- 如何在Eclipse中查看Java类库的源代码以及相应的api
- php数组和xml之间相互转化
- 51nod 1101 完全背包
- 计蒜客 数据结构 链表 ——应用筛选简历 C++
- Float Vs BigDecimal
- FastJSON
- IOS友盟 社会化分享 > 社会化iOS组件 > 分享集成
- 百度地图API -- 开发总结
- CSS基础-引入方法,选择器,继承
- POJ 1363 (简单栈)UVA 514
- 从腾讯文化VS阿里文化看滴滴和UBER的并购事件
- XML解析(DOM SAX JDOM DOM4J)