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
Ladders are a fundamental piece of equipment on construction sites and employers are expected to ensure that workers follow safe
Ede4ka [16]
That statement is true.

Ladders commonly used to do a couple of construction activities in a higher region of a building or area.
If this equipment is not used properly, it could potentially caused  fatal accidents for the people on the site
6 0
3 years ago
71 81 77 15 63 96 36 51 77 18 17
sp2606 [1]

Answer:

Following are the solution to this question:

Explanation:

This algorithm uses the divide and rule approach works, which splits the list into two sublists depending on if they are smaller or larger than the pivotal factor. It has O(n*log n) complexity.

It splits down the list in more than one version frequently till every sublist becomes based on a single element and fuses it to offer an ordered array. The merge type works according. It has O(n*log n) complexity.

Please find the attachment file of the sorting.

4 0
3 years ago
Which of the following is another term for a subfolder?
LenKa [72]
Subdirectory

Have a great day! c:
5 0
2 years ago
Anisha was learning ‘for’ and ‘while’ loop. Help her understand why for and while loops are called entry controlled loops.
Andrew [12]

Entry controlled loop - <u>The loop which has a condition check at the entrance of the loop, the loop executes only and only if the condition is satisfied is called as entry control loop.</u>

So, for and while loops are its examples.

6 0
2 years ago
Which one should i get?
Stella [2.4K]

Answer:

Explanation:

third

5 0
2 years ago
Read 2 more answers
Other questions:
  • Theresa is a certified teacher. She just had a baby and would like to stay home, but still wants to teach. Which career would be
    11·2 answers
  • Which category of app does word processing software fall into? A. Productivity B. Entertainment C. Social networking D. Educatio
    14·2 answers
  • Your company is instituting a new security awareness program. You are responsible for educating end users on a variety of threat
    10·1 answer
  • Select the correct answer.
    10·2 answers
  • Write a formula that would return a TRUE result if the sum of the first five numbers in a column of data are negative
    7·1 answer
  • What is the exclusive legal right granted to all authors and artists that gives them sole ownership of their work to print, publ
    5·2 answers
  • What are the steps to open the Custom AutoFilter dialog box?
    5·2 answers
  • A UI text element must be added to ______.an empty background container game objecta prefaba slot game objecta tray objecta canv
    6·1 answer
  • What is computer assisted translation​
    9·1 answer
  • What is an example of an assumption and dependency that an automated stocking application project would include in an SRS?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!