Advertisement
Hiteshw11

A function that takes a list and an integer n as input and rotates the list by n positions to the le

Nov 17th, 2024
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.33 KB | Source Code | 0 0
  1. //  a function that takes a list and an integer n as input and rotates the list by n positions to the left.
  2.  
  3. void main() {
  4.   List<int> nums=[10,20,30,40,50];
  5.   int n=2;
  6.   List<int> nums2=[];
  7.   for(int i=n;i<nums.length;i++)
  8.   {
  9.     nums2.add(nums[i]);
  10.   }
  11.   for(int j=0;j<n;j++)
  12.   {
  13.     nums2.add(nums[j]);
  14.   }
  15.   print(nums2);
  16. }
Tags: dart
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement