-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLinkedList(List K-Append).cpp
More file actions
65 lines (55 loc) · 1.33 KB
/
Copy pathLinkedList(List K-Append).cpp
File metadata and controls
65 lines (55 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//Problem Statement
/* Given a linked list of length N and an integer K , append the last K elements of a linked list to the front. Note that K can be greater than N.
Input Format
First line contains a single integer N denoting the size of the linked list.
Second line contains N space separated integers denoting the elements of the linked list.
Third line contains a single integer K denoting the number of elements that are to be appended.
Constraints
1 <= N <= 10^4
1 <= K <= 10^4
Output Format
Display all the elements in the modified linked list.
Sample Input
7
1 2 2 1 8 5 6
3
Sample Output
8 5 6 1 2 2 1
*/
#include<iostream>
#include<list>
using namespace std;
int main()
{
list <int> l;
int length;
cin>>length;
int a[length];
list <int> l3;
for(int i = 0 ; i < length ; i++)
{
cin>>a[i];
l3.push_back(a[i]);
}
int key;
cin>>key;
if(key > length)
{
key = key % length;
}
list <int> l2;
int b;
for (int i = length-key ; i < length ; i++)
{
l2.push_back(a[i]);
}
for(int i = 0 ; i <length-key ; i++)
{
l2.push_back(a[i]);
}
for(int i : l2)
{
cout<<i<<" ";
}
return 0;
}