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 triangle of numbers in reverse pattern

  2. Program to interchange the Small and Capital Letters and Unload the TSR after 10 seconds using Timer Interrupt

  3. LAGRANGES INTERPOLATION METHOD FOR FINDING X

  4. Program to find volume of sphere

  5. PROGRAM USING WHILE LOOP TO DO SUM OF DIGITS OF THE NUMBER. NO IS - 12345 ANS IS 15

  6. Program to compare number is greater than 100 or not using if statement

  7. PROGRAM SHOWING ROUND-OFF ERRORS IN FLOATING POINT COMPUTATIONS

  8. Program to copy elements of one array to another for n number of processes

  9. Program to input number is prime or not

  10. Program to read two positive numbers and interchange its values using *(mul) and /(div) operators and without using any extra variable

  11. Program to compute sum of those integers that are evenly divisible by 5. Use the conditional operator ( ? : )

  12. Program to multiply matrix (10 x 10) with a vector using variation in Loop Splitting using multiple barriers

  13. Program of Matrix-vector multiplication

  14. Program of finding Maximum and minimum of an array using Loop Splitting

  15. Inventory report

  16. Use of command line arguments

  17. Program of 2-thread for Linux Using the POSIX threads library. Once the thread spawning is done, the first thread should wait for user input

  18. Find Economic Order Quantity for a single item is given by EOB = sqrt(2 * demand rate * setup costs/holding costiong per item unit time)

  19. Program to display textbox works like the normal textbox found in Windows

  20. Program to compare one string s2 to another string s1. Print the difference of first unmatched characters using strcmp function from string.h

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