C Programming Tutorial

 
 
 
 

Image

#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;
    }

}

    Related Post:
  1. Program to print pyramid of * (stars) in reverse pattern

  2. Program that takes a number from user and calculates its logarithm value to the base 10 and e, exponentiation, sin value, cosine value and square root

  3. Program to find vowel Occurances from a given string

  4. Compute the yearly depreciation of the value of an item is given by DEPREATION = (PURCHASE VALUE - SALVAGE VALUE) / YEAR OF SERVICE

  5. Program to append one string s2 to another string s1 i.e. concatenation of two strings. (Use strcat function from string.h)

  6. Program of BAIRSTOWS METHOD

  7. Program to print triangle in opposite pattern

  8. PROGRAM FOR MAX and MIN OF ARRAY USING SPIN LOCK

  9. Program of an orphan

  10. Program of histogram using self-scheduling and locking the whole bin

  11. Program to count word from user entered text or sentence

  12. Program to check if given strings form an acrostic

  13. Program to perform sorting on words or string values using for loop

  14. Program to compute total cost including different taxes

  15. Recursive program to generate fibonacci Series

  16. PROGRAM TO FIND ANSWER OF THE FOLLOWING SERIES. INPUT STEPS FROM KEYBOARD. 1 + 2 + 6 + 24 + 120 + ......

  17. Program that accepts characters in lower case, stores them in an array and prints them in the upper-case

  18. Program to find process id and parent process id

  19. Program to display inputted string in ascending triangle and descending triangle

  20. Program to read the following numbers,round them off to the nearest integers and print out the results in integer form: 35.7 50.21 -23.73 -46.45

 
 
Didn't find what you were looking for? Find more on Program of link list