You are on page 1of 3

8/21/2021 QUES_8_D6 | DS_DAY_6 Question | Contests | HackerRank

NEW 31
PRACTICE CERTIFICATION COMPETE JOBS LEADERBOARD  Search   atulstar900

All Contests

DS_DAY_6

QUES_8_D6

QUES_8_D6

Problem Submissions Leaderboard Discussions

  
Given two doubly linked list, write a program to combine/concatenate the doubly linked list .
Contest ends in
a day
Input Format
Submissions:
332
NA
Max Score:
10
Constraints Difficulty: Medium

NA Rate This Challenge:







Output Format
More

NA

Sample Input 0

List 1: 2 4 6 8 10

List 2: 1 3 5 7 9

Sample Output 0

Combined list: 2 4 6 8 10 1 3 5 7 9

Explanation 0

NA

Current Buffer
(saved locally, editable)
  

 C  

1 ▾#include <stdio.h>
2 #include <string.h>
3 #include <math.h>
4 #include <stdlib.h>
5
6 ▾struct node{
7 int data;
8 struct node* prev;
9 struct node* next;
10 };
11 int main()
12 ▾{
13 struct node *npo=(struct node*)malloc(sizeof(struct node));
14 struct node *ptr=(struct node*)malloc(sizeof(struct node));
15 struct node *temp=(struct node*)malloc(sizeof(struct node));
16 struct node *rp1=(struct node*)malloc(sizeof(struct node));
17 struct node *rp2=(struct node*)malloc(sizeof(struct node));
18 npo->data=2;
19 npo->prev=0;
20 npo->next=ptr;
21 ptr->data=4;
22 ptr->prev=npo;
23 ptr->next=temp;
24 temp->data=6;

https://www.hackerrank.com/contests/ds-day-6/challenges/ques-8-d6 1/3
8/21/2021 QUES_8_D6 | DS_DAY_6 Question | Contests | HackerRank
25 temp->prev=ptr;
26 temp->next=rp1;
27 rp1->data=8;
28 rp1->prev=temp;
29 rp1->next=rp2;
30 rp2->data=10;
31 rp2->next=0;
32 rp2->prev=rp1;
33 struct node *npo1=(struct node*)malloc(sizeof(struct node));
34 struct node *ptr1=(struct node*)malloc(sizeof(struct node));
35 struct node *temp1=(struct node*)malloc(sizeof(struct node));
36 struct node *rp3=(struct node*)malloc(sizeof(struct node));
37 struct node *rp4=(struct node*)malloc(sizeof(struct node));
38 npo1->data=1;
39 npo1->prev=0;
40 npo1->next=ptr1;
41 ptr1->data=3;
42 ptr1->prev=npo1;
43 ptr1->next=temp1;
44 temp1->data=5;
45 temp1->prev=ptr1;
46 temp1->next=rp3;
47 rp3->data=7;
48 rp3->prev=temp1;
49 rp3->next=rp4;
50 rp4->data=9;
51 rp4->next=0;
52 rp4->prev=rp3;
53 npo->data=2;
54 npo->prev=0;
55 npo->next=ptr;
56 ptr->data=4;
57 ptr->prev=npo;
58 ptr->next=temp;
59 temp->data=6;
60 temp->prev=ptr;
61 temp->next=rp1;
62 rp1->data=8;
63 rp1->prev=temp;
64 rp1->next=rp2;
65 rp2->data=10;
66 rp2->next=npo1;
67 rp2->prev=rp1;
68 npo1->data=1;
69 npo1->prev=rp2;
70 npo1->next=ptr1;
71 ptr1->data=3;
72 ptr1->prev=npo1;
73 ptr1->next=temp1;
74 temp1->data=5;
75 temp1->prev=ptr1;
76 temp1->next=rp3;
77 rp3->data=7;
78 rp3->prev=temp1;
79 rp3->next=rp4;
80 rp4->data=9;
81 rp4->next=0;
82 rp4->prev=rp3;
83 struct node *temp4=(struct node*)malloc(sizeof(struct node));
84 temp4=npo;
85 printf("Combined list: ");
86 while(temp4!=0)
87 ▾{
88    printf("%d ",temp4->data);
89 temp4=temp4->next;
90 }
91 }
92

Line: 92
Col: 1

 Upload Code as File


Test against custom input Run Code
Submit Code

https://www.hackerrank.com/contests/ds-day-6/challenges/ques-8-d6 2/3
8/21/2021 QUES_8_D6 | DS_DAY_6 Question | Contests | HackerRank

Testcase 0 ✓

Congratulations, you passed the sample test case.


Click the Submit Code button to run your code against all the test cases.

Input (stdin)

List 1: 2 4 6 8 10

List 2: 1 3 5 7 9

Your Output (stdout)

Combined list: 2 4 6 8 10 1 3 5 7 9

Expected Output

Combined list: 2 4 6 8 10 1 3 5 7 9

Contest Calendar
|
Interview Prep
|
Blog
|
Scoring
|
Environment
|
FAQ
|
About Us
|
Support
|
Careers
|
Terms Of Service
|
Privacy Policy
|
Request a Feature

https://www.hackerrank.com/contests/ds-day-6/challenges/ques-8-d6 3/3

You might also like