Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- struct node{
- int data;
- struct node *next;
- };
- struct node *head=NULL;
- struct node *current=NULL;;
- int main(){
- insertItem(10);
- insertItem(100);
- insertItem(1000);
- printList(head);
- return 0;
- }
- void insertItem(int d){
- struct node *newNode=(struct node *)(malloc(sizeof(struct node)));
- newNode->data=d;
- newNode->next=NULL;
- if(head==NULL){
- head=newNode;
- current=head;
- }else{
- current->next=newNode;
- current=current->next;
- }
- }
- void printList(struct node *temp){
- while(temp!=NULL){
- printf("%d\n", temp->data);
- temp=temp->next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement