1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Vlad [161]
3 years ago
10

Write a routine to interchange the mth and nth elements of a singly-linked list. You may assume that the ranks m and n are passe

d in as parameters. Allow for all the ways that m and n can occur. You must rearrange the pointers, not simply swap the contents.
Computers and Technology
1 answer:
IRINA_888 [86]3 years ago
3 0

Answer:

//The routine to swap m th and nth ranked elements

void swapmAndn(int m, int n)

{

  //Set the linked list head node

  Linked_Node **node_head

  //To find the m ranked node

  //set previous node  

  Linked_Node *node_prev = NULL;

 

  //set node to store m ranked node as head node

  Linked_Node *node_current_m = *node_head;

 

  //set the rank as rm=1

  rm =1

  //traverse to find the m ranked node

  while (node_current_m && rm<m)

  {    

      node_prev = node_current_m;

      node_current_m = node_current_m->next;

      rm++;

  }

 

  //To find the n ranked node

  //set previous node  

  Linked_Node *node_prev_n = NULL;

 

  //set node to store n ranked node as head node

  Linked_Node *node_current_n = *node_head;

 

  //set the rank as rn=1

  rn =1

  //traverse to find the n ranked node

  while (node_current_n && rn<n)

  {    

      node_prev_n= node_current_n;

      node_current_n = node_current_n->next;

      rn++;

  }

 

  //if m is not first ranked node

  if (node_prev != NULL)

      //set node_current_n as previous node

      node_prev->next = node_current_n;

 

  //otherwise Set the node_current_n

  else

      *node_head = node_current_n;

 

  // If n is not first ranked node

  if (node_prev_n!= NULL)

      node_prev_n->next = node_current_m;

  else

      *node_head = node_current_m;

 

  //now swap the next pointers also

  //to make the swap process complete  

  Linked_Node *temp = node_current_n->next;

  node_current_n->next = node_current_m->next;

  node_current_m->next = temp;

}

Explanation:

You might be interested in
data structureWe have two containers: one has a capacity of three gallons of water, the other five gallons. Both are initially e
ra1l [238]

Answer:

Answer explained below

Explanation:

This problem can be represented on a graph by considering each state (or configuration) of the pair of containers as a vertex of the graph. We will be having 24 vertices, since the first container can have 0, 1, 2 or 3 gallons and the second can have 0, 1, 2, 3, 4 or 5 gallons of water. So, we will be having vertices like (0, 0), (0, 1), (0,5), (1, 0), (2, 3), (5, 5) etc.

The edges will be directed, and a vertex will be having an edge to it from another vertex if the configuration of the later vertex can be reached from the former vertex by any one of the legal moves. For example, from (2, 3) we can get (0, 5) by transferring the contents of the first container to the second. So there will be an edge from (2, 3) to (0, 5).

7 0
3 years ago
What are some industries of aerodynamics and hydrodynamics? explain each one in detail.
maria [59]
Aerodynamic- Wind turbine, computational fluid dynamics, and Wind power

Hydrodynamics- Computational Fluid Dynamics, Hydraulics, and Microfluidics
3 0
2 years ago
Read 2 more answers
Robert's employer has agreed to pay half the tuition for Robert to complete his college degree. This benefit is known as what?
slega [8]

Answer:

Educational reimbursement (Tuition reimbursement)

Explanation:

Educational reimbursement or tuition reimbursement is what an employer gives to his or her employee as a way to pack for education expenses. The employer pays an amount of money for college coursework to be applied toward a degree. Moreover, this tuition reimbursement is intended for employees who want to increase their knowledge.

8 0
4 years ago
Read 2 more answers
As you are planning your informative speech on the prevalence of Internet memes in pop culture and you wonder if your audience w
Tasya [4]

Answer:

i dont get it

Explanation:

what is the question?

4 0
3 years ago
I can talk to you! How about we talk through the you know where people comment and say stuff about the question1
pychu [463]
Hmmm what do you want to talk about??
3 0
3 years ago
Read 2 more answers
Other questions:
  • program that reads numbers from scanf (keyboard) and then sums them, stopping when 0 has been entered. Construct three versions
    14·1 answer
  • List the six external parts or peripherals of a computer system
    13·1 answer
  • Which of the following might not exist in a URL?
    10·2 answers
  • arlos, an algebra teacher, is creating a series of PowerPoint presentations to use during class lectures. After writing, formatt
    12·2 answers
  • Manuel is working on a project in Visual Studio. He wants to keep this program showing on the entire desktop, but he also needs
    13·1 answer
  • Which best describes obliteration in a forged document?
    11·1 answer
  • Function of C:\&gt;DIR*.doc/p​
    5·1 answer
  • HELP ME ON THIS PLEASE ILL GIVE BRAINLY!!!! If U GET IT RIGHT !!!
    10·1 answer
  • What are the different Stape of data processing cycle?​
    8·1 answer
  • Which of the following is NOT a media file? *<br> .wav<br> .mp4<br> .exe
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!