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
Which loan type requires you to make loan payments while you’re attending school?
tigry1 [53]
Direct Subsidized Loans I believe
7 0
3 years ago
Which page format would you likely use for a photograph of a standing tree? AND why would you use that format?
VladimirAG [237]
Portrait since it is more tall then wide
4 0
3 years ago
Literacy is best defined as knowing how to: (Points : 1)
iragen [17]
Read and write. Think of the term "literacy rate" it refers to how much of a population can read and write.
5 0
3 years ago
Read 2 more answers
Text that is heavier or darker than other text in the document is considered _____.
kvv77 [185]

The text that is heavier or darker than other text in a document is considered  Bold.

Hope this helped!~

7 0
3 years ago
Read 2 more answers
Suppose you have a file of data of approximately 100,000 personnel records (FYI, 213 = 8192 and 214 = 16384) using Social Securi
Natali [406]

Answer:

See explaination

Explanation:

The reasons why indexed sequential search structure is better are:

1. In index sequential search any field of the records can be used as the key. This key field can be numerical or alphanumerical.

2. Since each record has its data block address, searching for a record in larger database is easy and quick. There is no extra effort to search records. But proper primary key has to be selected to make efficient.

3. This method gives flexibility of using any column as key field and index will be generated based on that. In addition to the primary key and its index, we can have index generated for other fields too. Hence searching becomes more efficient, if there is search based on columns other than primary key.

The reasons why 5 B-tree is better:

1.The B-tree Provides support for range of queries in an efficient manner and You can iterate over an ordered list of elements.

2. B-Tree algorithms are good for accessing pages (or blocks) of stored information which are then copied into main memory for processing. In the worst case, they are designed to do dynamic set operations in O(lg n) time because of their high "branching factor" (think hundreds or thousands of keys off of any node). It is this branching factor that makes B-Trees so efficient for block storage/retrieval, since a large branching factor greatly reduces the height of the tree and thus the number of disk accesses needed to find any key.

3. It is a generalization of a BST in that a node can have more than two children. These are self-balancing and hence the average and worst complexities is logarithmic. We opt for these when the data is too huge to fit in main memory. These structures are used in database indexing and help in faster operations on disk

the additional informations is we should first decide to choose which structure is suiatable for which algoritm in terms of space and time and then use the appropriate search algorithm.

8 0
3 years ago
Other questions:
  • Question 14. (3.04 MC) how does the project manager evaluate the scope of a project
    14·1 answer
  • An example of how a merge field will appear in a document is ______.
    7·2 answers
  • What is renewable energy
    13·2 answers
  • Taking away iPad privileges when a student hits another child would be considered a(an) ________ principle for decreasing or ext
    10·1 answer
  • When does information become a liability for an organization
    6·1 answer
  • Which best describes a hybrid drive?
    11·1 answer
  • In an income statement subtracting the cost of goods sold from the net sales provides the?
    11·1 answer
  • If a document is stored on a file server but team members can edit the document​ anonymously, the content on the file server is:
    14·1 answer
  • What is a key differentiator for Accenture when delivering Artificial Intelligence (AI) solutions to clients?
    11·1 answer
  • What keyword is used in Java to create a parent/child relationship between two classes?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!