Problem:
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.
If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is.
You may not alter the values in the nodes, only nodes itself may be changed.
Only constant memory is allowed.
For example,
Given this linked list: 1->2->3->4->5
For k = 2, you should return: 2...
#include<iostream>using namespace std;class Node{public: Node(int value) : value(value), next(NULL) {}public: int value; Node* next;};Node* reverseList(Node* head){ Node* newList = NULL; Node* current = head; while (current) { Node* next = current->next; current->next = newList; newList = current; current = next; } return newList;}void printLi...
#include <iostream>
#include <algorithm>
usingnamespace std;int main()
{string a;getline(cin,a);reverse(a.begin(),a.end());cout<<a;return0;
} 原文:https://www.cnblogs.com/deadpool520/p/11055363.html
原文章地址:C++语言中反转字符串的函数strrev(), reverse() ,作者:王陸 (侵删)
1.使用string.h中的strrev函数
1 #include<stdio.h>
2 #include<string.h>
3 int main()
4 {
5 char s[]="hello";
6 strrev(s);
7 puts(s);
8 return 0;
9 }2.使用algorithm中的reverse函数1 #include <iostream>2 #include <string>3 #include <algorithm>4 using namespace std;5 int main()6 {7 string s= "hello";8 ...