Question

In: Computer Science

Linked List: Complete the following code to create a linked list from an Array. After creating...

Linked List:

Complete the following code to create a linked list from an Array. After creating the list, display the elements of the linked list iteratively.

Write two others function called as RDisplayTailRecursion(first) and RDisplayTailRecursion(first) which will print elements of the linked list using the tail and head recursions respectively.

#include <stdio.h>
#include <stdlib.h>
struct Node
{


}*first=NULL;

void create(int A[], int n)
{
for(i=1; i<n; i++)
{

}

}

void Display(struct Node*p)
{
while(p!=NULL)
{
}
}

void RDisplayTailRecursion (struct Node*p)
{

if(p!=NULL)
{
  
}
}

void RDisplayHeadRecursion (struct Node*p)
{

if(p!=NULL)
{
  
}
}


int main()
{
struct Node *temp;
int A[] = {3,5,7,10,25,8,32,2};
create(A,8);
Display(first);
printf("\n");


RDisplayTailRecursion(first);

RDisplayTailRecursion(first);
return 0;
}

Solutions

Expert Solution

If you have any doubts, please give me comment...

#include <stdio.h>

#include <stdlib.h>

struct Node

{

    int data;

    struct Node *next;

} *first = NULL;

void create(int A[], int n)

{

    int i;

    for (i = 1; i < n; i++)

    {

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

        newNode->data = A[i];

        newNode->next = NULL;

        if(first==NULL){

            first = newNode;

        }

        else{

            struct Node *temp = first;

            while(temp->next!=NULL){

                temp = temp->next;

            }

            temp->next = newNode;

        }

    }

}

void Display(struct Node *p)

{

    while (p != NULL)

    {

        printf("%d ", p->data);

        p = p->next;

    }

    printf("\n");

}

void RDisplayTailRecursion(struct Node *p)

{

    if (p != NULL)

    {

        printf("%d ", p->data);

        RDisplayTailRecursion(p->next);

    }

}

void RDisplayHeadRecursion(struct Node *p)

{

    if (p != NULL)

    {

        RDisplayHeadRecursion(p->next);

        printf("%d ", p->data);

    }

}

int main()

{

    struct Node *temp;

    int A[] = {3, 5, 7, 10, 25, 8, 32, 2};

    create(A, 8);

    Display(first);

    printf("\n");

    RDisplayHeadRecursion(first);

    printf("\n");

    RDisplayTailRecursion(first);

    printf("\n");

    return 0;

}


Related Solutions

Please complete following c++ code asap using following prototypes complete each missing part / Linked list...
Please complete following c++ code asap using following prototypes complete each missing part / Linked list operations int getLength() const {return length;} void insertNode(College); bool deleteNode(string); void displayList() const; bool searchList(string, College &) const; }; main.cpp /*   Build and procees a sorted linked list of College objects. The list is sorted in ascending order by the college code. Assume that the college code is unique. */ #include <iostream> #include <fstream> #include <string> #include "LinkedList.h" using namespace std; void buildList(const string...
Given an array of Student type and size 10, create a linked list of students by...
Given an array of Student type and size 10, create a linked list of students by linking students with an odd index first and then linking students with an even index. Write a loop to print out the students in the linked list #include<iostream> #include<string> #include<fstream> using namespace std; const int NUM = 10; struct Student{ string fName; string lName; Student * next; }; int main() {        Student stuArr[NUM];        ifstream myfile;        myfile.open("Test.txt");        for(int i = 0;...
Given an array of Student type and size 10, create a linked list of students by...
Given an array of Student type and size 10, create a linked list of students by linking students with an odd index first and then linking students with an even index. Write a loop to print out the students in the linked list. #include #include #include using namespace std; const int NUM = 10; struct Student{ string fName; string lName; Student * next; }; int main() { Student stuArr[NUM]; ifstream myfile; myfile.open("Test.txt"); for(int i = 0; i < NUM; i++)...
Using the singly linked list code as a base, create a class that implements a doubly...
Using the singly linked list code as a base, create a class that implements a doubly linked list. A doubly linked list has a Previous link so you can move backwards in the list. Be sure the class is a template class so the user can create a list with any data type. Be sure to test all the member functions in your test program. c++
Can you make this singular linked list to doubly linked list Create a Doubly Linked List....
Can you make this singular linked list to doubly linked list Create a Doubly Linked List. Use this to create a Sorted Linked List, Use this to create a prioritized list by use. Bring to front those links recently queried. -----link.h------ #ifndef LINK_H #define LINK_H struct Link{ int data; Link *lnkNxt; }; #endif /* LINK_H */ ----main.cpp---- //System Level Libraries #include <iostream> //I/O Library using namespace std; //Libraries compiled under std #include"Link.h" //Global Constants - Science/Math Related //Conversions, Higher Dimensions...
What are the contents of the array after the for-loop in the following code?
(IN C)What are the contents of the array after the for-loop in the following code?int array[ SIZE ][ SIZE ] = { { 4, 5, 6, 7, 8 },{ 1, 2, 3, 4, 5 },{ 3, 6, 7, 8, 9 },{ 2, 3, 4, 5, 6 },{ 5, 6, 7, 8, 9 } };int i;int *ptr = array[ 0 ];for( i = 0; i < SIZE * SIZE; i++ ) {if( i % SIZE < 2 ) {*( ptr +...
Modify this linked list code to work with string. Insert the following items into the list...
Modify this linked list code to work with string. Insert the following items into the list and display the list. The items are: Pepsi, Coke, DrPepper, Sprite, Fanta. Insert them in that order. Display the list. Then delete DrPepper and redisplay the list. Then insert 7-UP and redisplay the list. Then append Water and redisplay the list. c++ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ #include <iostream> using namespace std; class ListNode { public:     int value;     ListNode *next;     ListNode(int nodeValue) {       value...
Modify the linked list code from class to work with strings. Insert the following food items...
Modify the linked list code from class to work with strings. Insert the following food items into the list and display the list. The items are: bread, noodles, milk, bananas, eggs. Insert them in that order. Display the list. Then delete milk and redisplay the list. Then insert ice cream and redisplay the list. Then append zucchini and redisplay the list. c++
C++ Linked Lists Practice your understanding of linked lists in C++ by creating a list of...
C++ Linked Lists Practice your understanding of linked lists in C++ by creating a list of songs/artist pairs. Allow your user to add song / artist pairs to the list, remove songs (and associated artist) from the list and be sure to also write a function to print the list! Have fun! Make sure you show your implementation of the use of vectors in this lab (You can use them too ) You MUST modularize your code ( meaning, there...
Using Linked List, create a Java program that does the following without using LinkedList from the...
Using Linked List, create a Java program that does the following without using LinkedList from the Java Library. and please include methods for each function. Create a menu that contains the following options : 1. Add new node at the end of LL. ( as a METHOD ) 2. Add new node at the beginning of LL. ( as a METHOD ) 3. Delete a node from the end of LL. ( as a METHOD ) 4. Delete a node...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT