Question

In: Computer Science

Explain and demonstrate a Linked List by adding following items into a Linked List: 10, 30,...

Explain and demonstrate a Linked List by adding following items into a Linked List: 10, 30, 15, 25 (show your work, you may write on paper and upload if you prefer)

Solutions

Expert Solution


#include<stdio.h>
#include<stdlib.h>
void insert(int n);
void display();
void deletetail();
void deletehead();
void deletepos(int n);
void insertpos(int n);
void inserthead();
struct node
{
        int data;
        struct node *link;
}*head,*tail;
void main()
{
        head=(struct node *)malloc(sizeof(struct node));
        int n;
        tail=head;
        printf("Enter an element: ");
        scanf("%d",&n);
        head->data=n;
        head->link=NULL;
        printf("Want to enter another element: y/n ");
        char c;
        scanf(" %c",&c);;
        while(c!='n')
        {
                printf("Enter element: ");
                scanf("%d",&n);
                insert(n);
                printf("Want to enter another element: y/n ");
                scanf(" %c",&c);
        }
        display();
        printf("\n");
}
void insert(int n)
{
        struct node *temp;
        temp=(struct node *)malloc(sizeof(struct node));
        tail->link=temp;
        temp->data=n;
        temp->link=NULL;
        tail=temp;
}

void display()
{
        struct node *temp;
        temp=head;
        if(!temp)
        {
                printf("No data is available");
                return;
        }
        while(temp)
        {
                printf("%d ",temp->data);
                temp=temp->link;
        }
}

Related Solutions

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...
write a program using Java language that is- Implement Stack with a linked list, and demonstrate...
write a program using Java language that is- Implement Stack with a linked list, and demonstrate that it can solve the Tower of Hanoi problem. Write implementation body of method “infixToPrefix(String[] e)” of class ArithmeticExpression to convert infix expressions into prefix expressions.
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++
Can you fix please? this is adding the given location of doubly linked list in java...
Can you fix please? this is adding the given location of doubly linked list in java but if I make reverse is not adding the new node that I added but is printing forward correctly. just fix to me that part public void addAtLocation(E newNode, int location) {        Node node = new Node(newNode);               node.data = newNode;               Node previous = head;                      int counter = 1;...
!Must be written in C++! Build a doubly linked list with these operations: AddToHead(10); AddToHead(20); AddToTail(30);...
!Must be written in C++! Build a doubly linked list with these operations: AddToHead(10); AddToHead(20); AddToTail(30); AddToTail(40); Build a sorted doubly linked list with these operations: Add(30), Add(20), Add(40), Add(15), Add(35);
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...
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...
Build a doubly linked list with these operations: AddToHead(10); AddToHead(20); AddToTail(30); AddToTail(40); Build a sorted doubly...
Build a doubly linked list with these operations: AddToHead(10); AddToHead(20); AddToTail(30); AddToTail(40); Build a sorted doubly linked list with these operations: Add(30), Add(20), Add(40), Add(15), Add(35);
Change program linkedListClass to the linked list for student items (a student item contains id, name...
Change program linkedListClass to the linked list for student items (a student item contains id, name and score, where the id is used as key) and test it in the main method. You can define a student item using a class of student. given the following codes; import java.util.*; public class linkedListClass {    public Node header;    public linkedListClass()    {        header = null;    }    public final Node Search(int key)    {        Node...
Java Generic 2D Linked List Problem How to convert a 1D linked List into multiple linked...
Java Generic 2D Linked List Problem How to convert a 1D linked List into multiple linked lists with sequential values together? //Example 1: [1,1,2,3,3] becomes [[1,1],[2],[3,3]] //Example 1: [1,1,2,1,1,2,2,2,2] becomes [[1,1],[2],[1,1],[2,2,2,2]] //Example 3: [1,2,3,4,5] becomes [[1],[2],[3],[4],[5]] public <T> List<List<T>> convert2D(List<T> list) { // Given a 1D, need to combine sequential values together. }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT