Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef struct s{
- int data;
- struct s *prev, *next;
- }node;
- int main(int argc, char const *argv[]){
- node *head, *temp;
- int i, n;
- head = new node;
- head -> prev = NULL;
- head -> next = NULL;
- scanf("%d", &n);
- scanf("%d", &(head->data));
- for(i = 1; i < n; i++){
- temp = new node;
- temp->prev = head;
- temp->next = NULL;
- head->next = temp;
- head = head->next;
- scanf("%d", &(head->data));
- }
- while(head != NULL){
- printf("%d ", head->data);
- head = head->prev;
- }
- return 0;
- }
- #include <bits/stdc++.h>
- using namespace std;
- typedef struct s{
- int data;
- struct s *prev, *next;
- }node;
- int main(int argc, char const *argv[]){
- node *head, *temp;
- int i, n;
- head = new node;
- head -> prev = NULL;
- head -> next = NULL;
- scanf("%d", &n);
- //
- //scanf("%d", &(head->data));
- for(i = 0; i < n; i++){
- temp = new node;
- temp->prev = head;
- temp->next = NULL;
- head->next = temp;
- head = head->next;
- scanf("%d", &(head->data));
- }
- // 0 based index (head->prev != NULL)
- // 1 based index (head != NULL) and ek input pehle lena padega
- while(head->prev != NULL){
- printf("%d ", head->data);
- head = head->prev;
- }
- return 0;
- }
- // C
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct s{
- int data;
- struct s *prev, *next;
- }node;
- int main(int argc, char const *argv[]){
- node *head, *temp;
- int i, n;
- head = (node*) malloc(sizeof(node));
- head -> prev = NULL;
- head -> next = NULL;
- scanf("%d", &n);
- //
- //scanf("%d", &(head->data));
- for(i = 0; i < n; i++){
- temp = (node*) malloc(sizeof(node));
- temp->prev = head;
- temp->next = NULL;
- head->next = temp;
- head = head->next;
- scanf("%d", &(head->data));
- }
- // 0 based index (head->prev != NULL)
- // 1 based index (head != NULL) and ek input pehle lena padega
- while(head->prev != NULL){
- printf("%d ", head->data);
- head = head->prev;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment