You are on page 1of 2

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

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

All Contests

DS_DAY_6

QUES_1_D6

QUES_1_D6

Problem Submissions Leaderboard Discussions

Write a program to create a doubly linked list.

Input Format

The first line of input contains n, the number of elements in the linked list. The next n lines contain one element each, the data
values for each node.

Constraints

NA

Output Format

NA

Sample Input 0

16

13

Sample Output 0

16

13

  

Contest ends in
a day

Submissions:
346
Max Score:
10
Difficulty: Medium

Rate This Challenge:







More

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 ▾{
https://www.hackerrank.com/contests/ds-day-6/challenges/ques-1-d6 1/2
8/21/2021 QUES_1_D6 | DS_DAY_6 Question | Contests | HackerRank
13    struct node *head=(struct node*)malloc(sizeof(struct node));
14 struct node *ptr=(struct node*)malloc(sizeof(struct node));
15 struct node *rp=head;
16 head->data=16;
17 head->prev=0;
18 head->next=ptr;
19 ptr->data=13;
20 ptr->prev=head;
21 ptr->next=0;
22 while(rp!=NULL)
23 ▾{
24 printf("%d\n",rp->data);
25 rp=rp->next;
26 }
27 }
28

Line: 27
Col: 2

 Upload Code as File


Test against custom input Run Code
Submit Code

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)

16

13{-truncated-}

Your Output (stdout)

16

13

Expected Output

16

13

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-1-d6 2/2

You might also like