Advertisement
Hydrase

Linked List

Aug 6th, 2024
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #define null 0
  4. struct node
  5. {
  6. int data;
  7. struct node *ptr;
  8. };
  9. typedef struct node node;
  10. class linklist
  11. {
  12. node *head;
  13. public:void create(void);
  14. void display(void);
  15.  
  16. };
  17. void linklist::create(void)
  18. {
  19. char choice;
  20. do
  21. {
  22. node *newnode,*temp;
  23. newnode=new node;
  24. cout<<"enter the data : \n";
  25. cin>>new node->data;
  26. newnode->ptr=null;
  27. if(head==null)
  28. {
  29. head=temp=newnode;
  30. }
  31. else
  32. {
  33. temp->ptr=newnode;
  34. temp=newnode;
  35. }
  36. cout<<"do you want to continue(y/n) :";
  37. cin>>choice;
  38. }while(choice=='y');
  39. }
  40. void linklist::display(void)
  41. {
  42. node *temp;
  43. temp=head;
  44. while(temp!=null)
  45. {
  46. cout<<temp->data;
  47. cout<<"->";
  48. temp=temp->ptr;
  49. }
  50. cout<<"null";
  51. }
  52. int main()
  53. {
  54. linklist li;
  55. clrscr();
  56. cout<<"\n creation";
  57. li.create();
  58. cout<<"\n display";
  59. li.display();
  60. getch();
  61. return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement