Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

Program of link list

Posted By: Easy Tutor     Category: C Programming     Views: 4451

Write a program that creates and displays link list.

Code for Program of link list in C Programming

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

struct node
{
int data;
struct node *next;
};

void main()
{
  struct node *create(),*head;
  void display(struct node *);
  int count(struct node *);
  void sort(struct node *);
  int key;
  clrscr();
  while(1){
      if(key==27)
     break;
      else{
       head=create();
       display(head);
       sort(head);
      }
      printf("\nPress Escape to return...");
      key=getch();
  }
}

struct node *create(void){
   struct node *start=NULL,*newl=NULL,*endl=newl;
   int take;
   while(1){
       printf("\nEnter -1 at endto terminate\n");
       printf("Enter data : ");
       scanf("%d",&take);
       if(take==-1)
      break;
       else{
       newl = (struct node *)malloc(sizeof(struct node));
       newl->data = take;
       if(start==NULL)
          start=newl;
       else
          endl->next = newl;
       endl=newl;
       endl->next=NULL;
       }
   }
   return(start);
}


void display(struct node *start){
  printf("\ndisplay\n");
  while(start!=NULL){
   printf("%d",start->data);
   if(start->next!=NULL)
      printf("==>");
   start=start->next;
  }
}

int count(struct node *start){
    int cnt=0;
    while(start!=NULL){
       cnt++;
       start = start->next;
    }
    return(cnt);
}


void sort(struct node *start){
   struct node *temp1=start,*temp2=start;
   int tmpdata;
    while(temp1!=NULL){
    while(temp2->next!=NULL){
        if(temp1->data > temp2->next->data){
        tmpdata           = temp2->next->data;
        temp2->next->data = temp1->data;
        temp1->data       = tmpdata;
        }
        temp2=temp2->next;
    }
    temp1=temp1->next;
    }

}
  
Share: 


Didn't find what you were looking for? Find more on Program of link list Or get search suggestion and latest updates.

Easy Tutor
Easy Tutor author of Program of link list is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!