TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Addition in Linked List
Kaushik S
Nov 16
2015
Code
754
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
typedef
struct
node{
int
data;
struct
node* next;
}node;
struct
node* head;
void
insertAtEnd(
int
x)
{
struct
node* temp=NULL;
temp=(node*)malloc(
sizeof
(
struct
node));
temp->data=x;
if
(head==NULL)
{
head=temp;
temp->next=NULL;
}
else
{
struct
node* temp2=NULL;
temp2=(node*)malloc(
sizeof
(
struct
node));
temp=head;
while
(temp->next!=NULL)
{
temp=temp->next;
}
temp->next=temp2;
temp2->data=x;
temp2->next=NULL;
}
}
void
print()
{
int
total=0;
struct
node* temp=head;
while
(temp!=NULL)
{
total=total+temp->data;
temp=temp->next;
}
printf(
"%d"
,total);
}
void
main()
{
insertAtEnd(1);
insertAtEnd(2);
insertAtEnd(3);
insertAtEnd(4);
insertAtEnd(5);
print();
getch();
}
C
Datastructures