Advertisement
rafid_shad

4(1)

Nov 20th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. struct node
  4. {
  5.     char data;
  6.     int fre;
  7.     struct node *next;
  8. };
  9.  
  10.  
  11. struct node *head=NULL,*temp,*s;
  12.  
  13.  
  14. void display()
  15. {
  16.     temp=head;
  17.     while(temp!=NULL)
  18.     {
  19.         cout<<temp->data<<" "<<temp->fre<<endl;
  20.         temp=temp->next;
  21.     }
  22. }
  23.  
  24.  
  25. int main()
  26. {
  27.     int n,i;
  28.     char alpha='a';
  29.  
  30.     for(i=1; i<=26; i++)
  31.     {
  32.         struct node *newnode;
  33.         newnode=(struct node*) malloc (sizeof(struct node));
  34.         newnode->data=alpha;
  35.         newnode->fre=0;
  36.         newnode->next=NULL;
  37.  
  38.             if(head==NULL)
  39.             {
  40.                 head=newnode;
  41.                 s=head;
  42.             }
  43.  
  44.             else
  45.             {
  46.                 s->next=newnode;
  47.                 s=newnode;
  48.             }
  49.             alpha++;
  50.  
  51.     }
  52.  
  53.     display();
  54.  
  55.     return 0;
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement