rotate-list
来源:互联网 发布:java接口的特点 编辑:程序博客网 时间:2024/04/29 08:41
http://oj.leetcode.com/problems/rotate-list/
#include<stdio.h>#include<stdlib.h>#include<iostream>#include<vector>#include<string.h>#include<cstdarg>#define NUM 5using namespace std;struct ListNode {int val;ListNode *next;ListNode(int x) : val(x), next(NULL) {}};class Solution {public:ListNode *node[NUM];ListNode *pHead;void creatList(){node[0]=new ListNode(1);pHead = node[0];ListNode *p = node[0];for(int i=1;i<NUM;i++){node[i]=new ListNode(i+1);p->next=node[i];p = node[i];}}void printL(){ListNode *p =NULL;int i;for(i=0,p=pHead;(p!=NULL)&&(i<NUM-1);p=p->next,i++){cout << p->val << "->";}cout<<p->val;//这里打印cout >>endl就出错。printf("\n");}ListNode *rotateRight( int k){int listLen;int i=0;//从倒数第k数截断链表for(;i<NUM-k;i++){}pHead=node[i];node[i-1]->next=NULL;//重组链表node[NUM-1]->next=node[0];return pHead;}};int main(){Solution rotate;rotate.creatList();rotate.printL();rotate.rotateRight(2);rotate.printL();return 0;}
0 0
- Rotate List
- Rotate List
- Rotate List
- Rotate List
- Rotate List
- Rotate List
- Rotate List
- Rotate List
- Rotate List
- Rotate List
- Rotate List
- rotate-list
- Rotate List
- Rotate List
- Rotate List
- Rotate List
- Rotate List
- Rotate List
- 厨房用具,将吸目无背无侧旁
- Bug管理系统UML2.0建模实例(三)
- Opencv2系列学习笔记10(提取连通区域轮廓)
- 黑马程序员_温习 IO流四 (个人笔记)摘要(打印流PrintWriter(Stream)---序列流SwquenceInputStream----对象流ObjectInputStream(Outp
- C++模板学习
- rotate-list
- Linux磁盘系统基础知识
- vc将彩色图像转换为灰度图像
- 黑马程序员_温习 IO流五 (个人笔记)摘要(字符编码)
- 内核中与驱动相关的内存操作之一(MMU)
- NYOJ 67 三角形面积
- 二进制的表白
- AS3 对JSON的读取和发送
- 网络扫描技术揭秘读书笔记3--TCP SYN扫描