Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct node
- {
- int a;
- struct node *next;
- } node;
- node *head;
- void enqueue(int aN)
- {
- node *N=(node*)malloc(sizeof(node));
- N->a=aN;
- N->next=NULL;
- if(head==NULL)
- {
- head=N;
- }
- else
- {
- node *list=head;
- while(list->next!=NULL)
- {
- list=list->next;
- }
- list->next=N;
- }
- }
- int dequeue()
- {
- int data=0,n;
- node*temp;
- temp=head;
- data=head->a;
- head=head->next;
- free(temp);
- return data;
- }
- int main()
- {
- int n,x,i;
- head=NULL;
- printf("Input the Number of Node:");
- scanf("%d",&n);
- for(i=0; i<n; i++)
- {
- scanf("%d",&x);
- enqueue(x);
- }
- int sum=0,z,q,l;
- for(l=0; l<n; l++)
- {
- q=dequeue();
- sum=sum+q;
- }
- printf("\nTotal SUM IS:%d",sum);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement