careercup2.1
来源:互联网 发布:mysql降序 编辑:程序博客网 时间:2024/06/13 10:23
熟悉链表操作。
/*Write code to remove duplicates from an unsorted linked list FOLLOW UPHow would you solve this problem if a temporary buffer is not allowed?*/#include <iostream>using namespace std;class Node{public:int data; Node* next;Node(){this->next = 0;}Node(int a):data(a),next(0){}};class LinkList{public:LinkList(){ head = new Node(-1);}LinkList(int ar[],int len){head = new Node(-1);Node*p = FindTail();for(int i = 0; i<len; i++)insertion(ar[i]);}Node* FindTail();Node* head;void insertion(int);Node* del(Node* i, Node*p);void checkredu();void print()const{Node* p = head->next; while(p){ cout<<p->data<<" "; p = p->next; }}};Node* LinkList::FindTail(){Node* p = head;while( p->next!= 0){p = p->next;}return p;}void LinkList::insertion(int k){Node* p = FindTail();p->next = new Node(k);}Node* LinkList::del(Node* i,Node*p){p->next = i->next;delete(i);return p->next;}void LinkList::checkredu(){Node* p = head->next;while(p){if(p->data == 67)p = p;Node* temp = p->next;Node* par = p;while(temp){while(temp && temp->data == p->data){ temp = del(temp,par);}if(!temp) break; //tail cutpar = temp;temp = temp->next;}p = p->next;}}int main(){int ar[]={1,3,5,67,8,9,45,78,9,33,12,3,5,4,67,67};LinkList ll(ar,16);ll.checkredu();ll.print();}
- careercup2.1
- careercup2
- careercup2.2
- careercup2.3
- careercup2.4
- careercup2.5
- CareerCup2.5
- careercup2.4
- CareerCup2.3 删除最中间那个,或者删除给出任意一个节点(只能得到这个节点的pointer)
- 1
- 1
- 1
- 1
- 1
- 1
- 1》
- 1
- 1
- 对比4个函数 isset in_array array_search array_key_exists 速率对比及初步分析原因
- ORACLE执行计划(7)---采用TRUNC(SYSDATE)-1方法 无法确定分区
- Ubuntu Linux 环境变量PATH设置
- Android 文件系统
- Date转换工具类
- careercup2.1
- ubuntu 11.10 如何显示出应用程序图标
- http基础
- VC给自定义按钮加上事件操作
- 国家气象局提供的天气预报接口(完整Json接口)
- 南走1公里东走1公里北走1公里回原点
- 【你不知道的Java】-【用ue 格式化sql 供StringBuffer 使用 】
- Oracle学习总结
- calloc或new分配的数组只能在第一个元素上释放