Code.GeekInterview.com
 
Code Samples C
 

DLL through SLL


Code ResourceAuthor: mig40000  

Difficulty Level: Expert

Published: 6th Jan 2010   Read: 1664 times  

Filed in: C
Add Comment


 

 

Sponsored Links


 

 

This will convert SLL to DLL without changing its structure.

 


Sample Code
  1. #include<stdio.h>
  2. #include<conio.h>
  3. struct n1
  4. {
  5. int data;
  6. struct n1 *addr;
  7. }*temp,*head,*t1,*last,*first,*temp1;
  8.  void main()
  9. {
  10. typedef struct n1 node ;
  11. int n,m,i,k,l=0,g,i1=0;
  12. clrscr();
  13. do
  14. {
  15. printf("nenter your choicen1.insert head noden2.insert at begginingn3.insert at middlen4.insert at lastn5.displayn6.exitn");
  16. scanf("%d",&n);
  17. switch(n)
  18. {
  19. case 1:
  20. l++;
  21. i1++;
  22. if(l==1)
  23. {
  24. head=(node *) malloc(sizeof(node));
  25. printf("enter the value of head noden");
  26. scanf("%d",&k);
  27. head->data=k;
  28. head->addr=NULL;
  29. }
  30. else
  31. printf("head node already createdn");
  32. break;
  33. case 2:
  34. if(l==0)
  35. printf("first insert head noden");
  36. else
  37. {
  38. temp=head;
  39. first=(node *) malloc(sizeof(node));
  40. printf("enter the value of noden");
  41. scanf("%d",&k);
  42. first->data=k;
  43. first->addr=head;
  44. head=first;
  45. first=temp;
  46. }
  47. break;
  48. case 3:
  49. if(l==0)
  50. printf("first create head noden");
  51. else
  52. {
  53. temp=head;
  54. t1=(node *) malloc(sizeof(node));
  55. printf("enter the value of noden");
  56. scanf("%d",&k);
  57. t1->data=k;
  58. printf("enter the position where to insertn");
  59. scanf("%d",&m);
  60. i=0;
  61. while(i<m-1)
  62. {
  63. temp=temp->addr;
  64. i++;
  65. }
  66. t1->addr=temp->addr;
  67. temp->addr=t1;
  68. }
  69. break;
  70. case 4:
  71. if(l==0)
  72. printf("first insert the head noden");
  73. else
  74. {
  75. last=(node *) malloc(sizeof(node));
  76. temp=head;
  77. printf("enter the value of noden");
  78. scanf("%d",&k);
  79. last->data=k;
  80. while(temp->addr!=NULL)
  81. {
  82. temp=temp->addr;
  83. }
  84. temp->addr=last;
  85. last->addr=NULL;
  86. }
  87. break;
  88. case 5:
  89. if(i1==0)
  90. printf("list is emptyn");
  91. else
  92. {
  93. printf("nthe link list isn");
  94. temp=head;
  95. temp1=NULL;
  96. g=0;
  97. while(temp!=NULL)
  98. {
  99. printf("[%u|%d|%u]-->",temp1,temp->data,temp->addr);
  100. temp=temp->addr;
  101. if(g==0)
  102. {
  103. temp1=head;
  104. g++;
  105. }
  106. else
  107. temp1=temp1->addr;
  108. }
  109. }
  110. break;
  111. case 6:
  112. exit(0);
  113. }
  114. }while(n<=6);
  115. getch();
  116. }
Copyright GeekInterview.com


Next Article: Swap 2 variables without using 3rd variable


 

Latest Code Samples

 

Popular Code Samples

 

Related Code Samples

 

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    



Popular Coders

# Coder NameHits
1. kaivalya198932312
2. mano.mithun19248
3. deepu0817246
4. meefriend4ever7824
5. chandrikakr7815
6. shashivaishnav6687
7. sadasivathavamani6563
8. venkatakrishnansvpr6437
9. Jimmy Zorald6277
10. sripri5431

Active Coders

Refined Tags