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
SOVA2 [1]
3 years ago
8

Write a program that creates a linked list object of 10 characters and creates a second list object containing a copy of the fir

st list, but in reverse order.
Computers and Technology
1 answer:
slamgirl [31]3 years ago
4 0

Answer:

Below code is in c++ with explanation.

Explanation:

Explanation is in comment format, any line starting with //.

#include <iostream>

#include <cstdlib>

using namespace std;

//creating a Node struct which holds node data

struct Node {  

  char data;  

  struct Node *next;  

};  

//creating variable of Node as head

// this head is the start point of ordered Linked list

struct Node* head = NULL;    

// This method is used to insert new value in node

void insert(char new_data) {  

// allocating the memory for new node

  struct Node* new_node = (struct Node*) malloc(sizeof(struct Node));  

// assigning the data to new node

  new_node->data = new_data;  

// If head == null then it means we are inserting first value

// it will return after creating first node and assign it to

// head as head is the entry point

  if(head == NULL){

    new_node->next=NULL;

   head=new_node;

    return;

  }

// Now we need to treverse to end of linked list

// that's why creating a lastNode variable  

// As we don't want our head to point any other node

// except first node

  Node* lastNode = head;

  while(lastNode->next != NULL){

   lastNode=lastNode->next;

  }

// as last node next will be null to end the traversing  

// on linked list

  new_node->next= NULL;

// assigning last node to its previous node  

  lastNode->next = new_node;  

   

}  

// This variable will hold the first node for reverse linklist

struct Node* reverseHead = NULL;    

// This method will reverse the ordered linklist

void reversLinkList(){

  Node* lastNode = head;

// traversing the ordered linklist

  while(lastNode!= NULL){

// creating new linked list

   struct Node* new_node = (struct Node*) malloc(sizeof(struct Node));  

   new_node->data = lastNode->data;  

   new_node->next = reverseHead;  

   reverseHead = new_node;  

   lastNode = lastNode->next;

  }

   

}

// display method will travers the linklist that

// was passed throw paramter

void display(Node* node) {  

  struct Node* ptr;

  ptr = node;

  while (ptr != NULL) {  

     cout<< ptr->data <<" ";  

     ptr = ptr->next;  

  }  

}  

// main method is the entry point of this program

int main() {  

// adding 10 nodes by calling insert method

  insert('a');

  insert('b');

  insert('c');

  insert('d');

  insert('e');

  insert('f');

  insert('g');

  insert('h');

  insert('i');

  insert('j');

  cout<<"The Ordered linked list is: ";

// calling display method with head to print ordered linklist

  display(head);  

  cout<<endl;

  cout<<"The Reversed linked list is: ";

// calling reversLinkList to reverse the ordered linklist

  reversLinkList();

// calling display method with reverseHead to display  

// reversed linklist

  display(reverseHead);

   

  return 0;  

}

You might be interested in
It is a science fiction but the answer is not science fiction.it States ;it's inventiveness,uncertainly and futuristic ideas typ
MAVERICK [17]

Answer:

The uncertainty of inventiveness and futuristic ideas usually deal with science and technology.

Inventibility is something uncertain which promotes a risk in any system in which it is inserted. With that, we can naturally associate it with the maintenance of science and technology, because both are in need of inventing new creations, which may or may not be effective for the defeat of uncertainties and the creation of certainties.

This is usually linked to futuristic ideas, which may not fit in today's society, but which impose improvements, or not, for societies in the future. Leading to the creation of more technologies and more sciences.

3 0
3 years ago
What is done to prevent a plan from becoming confusing because of too much detail
Elena L [17]
When providing instructions or rule to follow, it is important to make them as clear as possible. Simple commands follow by an example (when possible) are basic steps to deliver a precise massage. 
Another thing is to bare in mind who is receiving the instruction. The receptor should be apt to the plan knowing vocabulary, structures, etc. 
Last but not least, check if the receptor understood the plan, double check if you think it is necessary 
4 0
3 years ago
Write a function PrintShampooInstructions(), with int parameter numCycles, and void return type. If numCycles is less than 1, pr
PSYCHO15rus [73]

// Writing a C++ function

void PrintShampooInstructions(int numCycles){

if(numCycles < 1) // if  condition stands

cout<< "To few";

else if(numCycles >4)

cour<<"Too Many";

else{

// looping the variable for desired out put

for(int i=0;i<numCycles;i++)

cout<<i<<":"<<" Lather and rinse."<<endl;

}

}

6 0
3 years ago
Read 2 more answers
How do i take off securly from my chromebook
tatuchka [14]

Answer:

DONT GO TO THAT WEBSITE!!!!!!

7 0
3 years ago
Read 2 more answers
Which of the following artists was a pioneering American cartoonist and animator who inspired Walt Disney?
Troyanec [42]
Winsor McCay inspired Walt Disney. He also inspired Bill Watterson, the author of the Calvin and Hobbes comic books.
6 0
3 years ago
Read 2 more answers
Other questions:
  • G=D+(A+C^2)*E/(D+B)^3 Rewrite the above formula in terms of doing concurrent processing using cobegin and coend to identify thos
    12·1 answer
  • What is computer? Explain the characteristics of computer.<br>​
    12·1 answer
  • You are a psychologist who needs to provide a qualitative evaluation for IQ scores. Create a program that takes IQ scores (one a
    10·1 answer
  • Describe the Sign in process of an Email account.​
    6·1 answer
  • How to build aeroplain pls tell me I want to go to amereeca
    13·1 answer
  • You have added a table to your web page consisting of two columns and five rows, including the header row. in the first header c
    13·1 answer
  • An insurance company utilizes SAP HANA for its day-to-day ERP operations. Since they can’t migrate this database due to customer
    5·1 answer
  • Write an expression in Boolean algebra that evaluates to 1 when an odd number of bits of the number is 1 and 0 otherwise
    14·1 answer
  • should variables that contain numbers always be declared as integer or floating-point data types? why or why not? name potential
    9·1 answer
  • Which option best describes top-down design?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!