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]
4 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]4 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
Whe you read anything online how do you know whether or not is coming from a reliable source?
lorasvet [3.4K]

You can find the author and research his/her credibility

You can cross-reference the information to other documentations

You can investigate the credibility of the overall website or community. Teachers like to say that community sites like wikipedia aren't very reliable.

4 0
3 years ago
Read 2 more answers
A cookie recipe calls for the following ingredients:
Romashka [77]

def cookie_Recipe(recipe):

   

   sugar=(0.03125*recipe)

   butter=(0.02083333333*recipe)

   flour=(0.05729166666*recipe)

   LF1=round(sugar, 2)

   LF2=round(butter,2)

   LF3=round(flour, 2)

   print("You will need:")

   print(LF1, "cups of sugar")

   print(LF2, "cups of butter")

   print(LF3, "cups of flour")

   print("To make", recipe, 'cookies')

recipe=int(input("How many cookies do you want to make?\n"))

cookie_Recipe(recipe)

4 0
3 years ago
(image attached)
SVEN [57.7K]

Answer:      

The answer to this question is given below in the explanation section.

Explanation:

In this given program there are two errors, first in line number 2 that stores a string value, not int. The second error is at line 6, a symbol "*" represents multiplication, not addition.

To solve these errors, in line #2, convert the input to an int variable value 1. To add the values of variables (value1 and value2), use the plus symbol "+" in the print statement at line #6.

The correct program is given below:

<em>value1= int(input("Enter first number: "))</em>

#get second number and store it into value2 variable.

<em>value2= int(input("Enter second number: "))</em>

#add the values store in variables (value1 and value2) and then print

<em>print (value1 + value2)</em>

7 0
3 years ago
What protects original and creative expression of an idea?
alukav5142 [94]
A patent grants the right to sell an invention and claim it as your own
6 0
4 years ago
Read 2 more answers
Write a program that reads a value (n) and outputs "hello world" n times. if the value is 3 , the output will be "hello world" p
den301095 [7]
Is the value read from user input or from a file? Also, what language?
6 0
4 years ago
Other questions:
  • A password checking system that disallows user passwords that are proper names or words that are normally included in a dictiona
    15·1 answer
  • Brock wants to use several images on his hiking blog. However, the images are making his pages load very slowly. Explain to Broc
    6·1 answer
  • An administrator wants to configure hosts to automatically assign IPv6 addresses to themselves by the use of Router Advertisemen
    14·1 answer
  • )what item is at the front of the list after these statements are executed?
    15·1 answer
  • Write a c++ application that computes gross salary for Mr.A,given that during the interview session and before started work, it
    5·1 answer
  • How do i beat the final battle in lara croft: temple of osiris?
    9·1 answer
  • Where do you see the future of Information Technology heading?
    12·1 answer
  • Features of action files​
    15·1 answer
  • In securing the client/server environment of an information system, a principal disadvantage of using a single level sign-on
    12·1 answer
  • Hello :) new day <br> which one would u pick?<br> 1. chips 2. Gacha life 3. chocolate?<br><br> hehe
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!