Paste your code for that here (this should only be one line) |
Paste your code for that here |
Paste your code for that here |
a.) Struct Node {int value; Node* Next }; Node * arptr[2020];
b.) i)
void rotate_by_n(Node** head, int n)
{
Node* curr = *head;
Node* temp = *head;
int length = 1;//store number of nodes
while (temp->next != NULL) {
temp =
temp->next;
length++;
}
if(curr->next==NULL||curr==NULL) //if 0 or 1 node in list
{
return;
}
if (n == 0)
return;
if(n<0) //for left rotation
{
n=-(n);
if (n > length)
{
n = n % length; //if
n>count of nodes then we take modulus
}
Node* current1 = *head;
int count1 = 1;
while (count1 < n && current1 !=
NULL) {
current1 =
current1->next; // current1 will point to nth node after this
loop
count1++;
}
if (current1 == NULL)
return;
Node* nthnode = current1;
while (current1 ->next != NULL)
current1 =
current1->next;
current1->next = *head; // change to head
*head = nthnode->next; //change head to (nth+1) node
nthnode->next = NULL;
}
else if(n>0)
{
if (n > length)
n= n%length;
n= length-n;
if (n==0||n==length)
return;
Node* current1 = *head;
int count2= 1;
while (count2 < n && current1 !=
NULL) {
current1 =
current1->next;
count2++;
}
if (current1 == NULL)
return ;
Node* nthnode = current1;
temp->next = *head;
*head = nthnode->next;
nthnode->next = NULL;
}
}
b) ii)
void secondSwap(Node * head)
{
Node *
temp1=head,*temp2=head->next,*temp3=head,*curr=head;
while(curr->next->next!=NULL)
{
temp3=curr;
curr=curr->next;
}
if (temp1!= NULL)
temp1->next = curr;
else
{
head = curr;
}
if (temp3 != NULL)
temp3->next = temp2;
else
{
head = temp2;
}
Node *temp = curr->next;
curr->next = temp2->next;
temp2->next = temp;
}
void secondSwap(Node ** head)
C# code Arrays and Linked Lists: Write C++/Java/C#/Python code to declare an array of linked lists...
C++ pointers and linked lists 1. Declare an integer pointer variable intPointer. Initialize it to point to an int variable named someInt. Assign the value 451 to someInt and output (cout) the variable someInt and output (cout) the value pointed to by intPointer. Write an assignment statement that indirectly stores 900 into the value pointed to by intPointer. Output (cout) the value pointed to by intPointer and output (cout) the variable someInt, 2. Declare a pointer variable charArrPointer and initialize...
Write a C++ code to insert the following numbers in two Linked Lists. Insert numbers of first list in Linked List#1, and numbers of second list in Linked List#2. Do not insert both lists in a single Linked List. List#1. 5, 78, 45, 23, 11, 89, 10, 78, 6, 99, 876, 5, 67, 13 List#2. 5, 89, 688, 52, 557, 953, 5, 7, 55, 35, 89, 99, 99, 6, 557, 89, 5, 99, 6, 2, 45, 12, 7, 6, 94,...
java programming!!! Write the code fragment that will do the following: • Ask the user how many numbers they want to enter • Declare and instantiate an array of doubles with as many elements as the number entered by the user • Write one 'for' loop to fill the array with data from the user • Write a second 'for' loop to calculate the sum of all of the numbers in the array • Print the calculated sum Note: Write...
117% Question 1: Linked Lists Create an IntLinkedList class, much like the one presented in class. It should implement a linked list that will hold values of type int. It should use an IntNode class to implement the nodes in the linked list. The linked list must have the following methods: . A constructor with no parameters which creates an empty list. . void add (int data) -adds data to the front of the list. .A constructor IntlinkedList(int[]) which will...
Write Java code (do not use Java libraries) to perform the following on a linked list of integers: prepend a new value
Arrays, Lists, Stacks and Queues: 1) Write C++ code to reverse a singly-linked list L using only a constant amount of additional storage and no recursion. Assume the list object has a head pointer _head and consists of Node objects; a Node object has a pointer Node* _next
C++ You're given the pointer to the head nodes of two linked lists. Compare the data in the nodes of the linked lists to check if they are equal. The lists are equal only if they have the same number of nodes and corresponding nodes contain the same data. Either head pointer given may be null meaning that the corresponding list is empty. Input Format You have to complete the int CompareLists (Node headA, Node* head B) method which takes...
*Java* Hi. I need some help with creating generic methods in Java. Write a program GenMethods that has the following generic methods: (1) Write the following method that returns a new ArrayList. The new list contains the nonduplicate (i.e., distinct) elements from the original list. public static ArrayList removeDuplicates(ArrayList list) (2) Write the following method that shuffles an ArrayList. It should do this specifically by swapping two indexes determined by the use of the random class (use Random rand =...
Q1) How would you declare an array of doubles called myDoubles? Arrays can be initialized in one of two ways. In one method, the array elements are placed in a list enclosed in curly braces after the array name definition. For example, the code below creates an array of ints with 3 elements: 1, 2 and 3. int[] a = {1, 2, 3, 4}; We can also initialize an array with a new construct, indicating how many elements we want...
a) Declare and instantiate an array named scores of twenty-five elements of type int. (b)Write a statement that declares an array namedstreetAddress that contains exactly eighty elements of typechar. 2. In a single statement: declare, create and initialize an arraynamed a of ten elements of type int with the values of the elements (starting with the first) set to 10, 20,..., 100 respectively. 3. Declare an array reference variable, week, and initialize it to an array containing the strings "mon",...