Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #include<process.h>
  4. class node
  5. {
  6. public:
  7. int info;
  8. node *next;
  9. }*start,*newptr,*save,*ptr,*rear;
  10. node *create_new_node(int n)
  11. {
  12. ptr=new node;
  13. ptr->info=n;
  14. ptr->next=NULL;
  15. return ptr;
  16. }
  17. void Insert(node *np)
  18. {
  19. if(start==NULL)
  20. start=rear=np;
  21. else
  22. {
  23. rear->next=np;
  24. rear=np;
  25. }
  26. }
  27. void delnode()
  28. {
  29. if(start==NULL)
  30. cout<<"UNDERFLOW!!!\n";
  31. else
  32. {
  33. ptr=start;
  34. start=start->next;
  35. delete ptr;
  36. }
  37. }
  38. void display(node *np)
  39. {
  40. while (np!=NULL)
  41. {
  42. cout<<np->info<<" -> ";
  43. np=np->next;
  44. }
  45. cout<<"!!!\n";
  46. }
  47. void main()
  48. {
  49. start=rear=NULL;
  50. int inf;
  51. char ch='y';
  52. while (ch=='y'||ch=='Y')
  53. {
  54. clrscr();
  55. cout<<"\nEnter INFOrmation for the new node...";
  56. cin>>inf;
  57. newptr=create_new_node(inf);
  58. if (newptr==NULL)
  59. {
  60. cout<<"\nCannot create new node!!!Aborting!!\n";
  61. getch();
  62. exit(1);
  63. }
  64. Insert(newptr);
  65. cout<<"\nPress Y to enter more nodes,N to exit...\n";
  66. cin>>ch;
  67. }
  68. clrscr();
  69. do
  70. {
  71. cout<<"\nThe list now is: \n";
  72. display(start);
  73. getch();
  74. cout<<"Want to delete first node?(y/n)...";
  75. cin>>ch;
  76. if (ch=='y'||ch=='Y')
  77. delnode();
  78. }
  79. while(ch=='y'||ch=='Y');
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement