CareerCup-2.3
来源:互联网 发布:淘宝卖家怎么搞死同行 编辑:程序博客网 时间:2024/06/02 09:01
Implement an algorithm to delete a node in the middle of a single linked list, given only access to that node
EXAMPLE
Input: the node ‘c’ from the linked list a->b->c->d->e
Result: nothing is returned, but the new linked list looks like a->b->d->e
EXAMPLE
Input: the node ‘c’ from the linked list a->b->c->d->e
Result: nothing is returned, but the new linked list looks like a->b->d->e
#include <iostream>using namespace std;// Creating a Linked List:struct Node{ Node(int d):data(d){next = NULL;}; int data; Node* next;};void printNode(Node* head){ cout<<"Print:"<<endl; while(head != NULL) { cout<<head->data<<endl; head = head->next; } cout<<"End"<<endl;};void deleteMid(Node* p){ if(p == NULL || p->next == NULL) return; Node *q = p->next; p->data = q->data; p->next = q->next; delete q;};int main(){ Node* head = new Node(1); head->next = new Node(2); head->next->next = new Node(3); head->next->next->next = new Node(4); head->next->next->next->next = new Node(5); head->next->next->next->next->next = new Node(6); deleteMid(head->next->next); printNode(head); system("pause"); };
- CareerCup 2.3
- CareerCup-2.3
- CareerCup 1.3
- CareerCup 1.4
- CareerCup 5.7
- CareerCup 14.6
- CareerCup 1.1
- CareerCup 1.2
- CareerCup 1.3
- CareerCup 1.4
- CareerCup 1.5
- CareerCup 1.6
- CareerCup 1.7
- CareerCup 1.8
- CareerCup 2.1
- CareerCup 2.2
- CareerCup 2.4
- CareerCup 2.5
- LCD 驱动
- jquery中的toggle与slideToggle的区别
- linux下如何写RTC驱动
- CareerCup-2.2
- Bash Shell脚本学习小结
- CareerCup-2.3
- Java成长之路
- tomcat 乱码
- CareerCup-2.4
- final,finally,finalize的区别
- 自己编写的matlab zigzag排序算法
- uva11729 - Commando War
- java判断一个字符串对象是否在一个集合里面
- java 自学日志【十二】---工具类