utilizing
System;
public
class
LinkedList {
Node head;
public
class
Node {
public
int
information;
public
Node subsequent;
public
Node(
int
d)
{
information = d;
subsequent =
null
;
}
}
Node leftRotate(
int
x,
int
y)
{
Node prev = reverse(head, x,
y - x,
true
);
return
reverse(prev, y, y,
true
);
}
Node reverse(Node head,
int
m,
int
n,
bool
isfirstHalf)
{
if
(head ==
null
)
return
null
;
Node present = head;
Node subsequent =
null
;
Node prev =
null
;
int
rely = 0, okay = m;
if
(!isfirstHalf)
okay = n;
whereas
(rely < okay && present !=
null
) {
subsequent = present.subsequent;
present.subsequent = prev;
prev = present;
present = subsequent;
rely++;
}
if
(subsequent !=
null
)
head.subsequent
= reverse(subsequent, m, n,
!isfirstHalf);
return
prev;
}
void
push(
int
new_data)
{
Node new_node =
new
Node(new_data);
new_node.subsequent = head;
head = new_node;
}
void
printList()
{
Node temp = head;
whereas
(temp !=
null
) {
Console.Write(temp.information +
" "
);
temp = temp.subsequent;
}
Console.WriteLine();
}
public
static
void
Important()
{
LinkedList llist =
new
LinkedList();
for
(
int
i = 100; i >= 10; i -= 10)
llist.push(i);
Console.WriteLine(
"Given listing"
);
llist.printList();
llist.head = llist.leftRotate(2, 4);
Console.WriteLine(
"Rotated Linked Checklist"
);
llist.printList();
}
}