Saturday, November 24, 2012

OCT/NOV-2012(c-05)


C-09-CM-402
457
BOARD DIPLOMA EXAMINATION, (C-05)
OCT/NOV-2012
DCME-FOURTH SEMESTER EXAMINATION
Time: 3 hours]                   [Total Marks: 80
PART-A
Instructions: (1) Answer all questions
Each question carries three marks.
 Answers should be brief and straight to the point and shall not exceed five simple sentences.
1.       What is linked list? Give example.
2.       State the applications of stack.
3.       What is priority queue?
4.       Define complete binary tree.
5.       List various tree traversal techniques.
6.       Write the uses of sparse matrix.
7.       What are the different representations of tree in memory?
8.       List various sorting techniques.
9.       What is merge sort?
10.   Define ‘binary search’. Give an example.
PART-B
Instructions: (1) Answer any five questions.
(2) Each question carries ten marks.
(3) Answers should be comprehensive and the criteria for valuation is the content but not the length of the answer
11.   (a) write a c program for insertion operation on a single-linked list. (b) explain double-linked circular list with an example.
12.   Explain the algorithm for conversion of infix to postfix expression with an example.
13.   (a) explain the implementation of queue using linked list. (b) write a short note on circular queue.
14.   Write a c program to perform traversal operations on tree.
15.   (a) explain linked representation of binary tree with an example. (b) explain binary search sort.
16.   Explain with a program for operations on binary tree for integers.
17.   (a) explain the principle of quick sort with an example. (b) write a c program for selection sort.
18.   (a) explain about abstract data types. (b) explain linear search technique with example.



Answers:

PART-A

19.   What is linked list? Give example.
20.   State the applications of stack.
21.   What is priority queue?
22.   Define complete binary tree.
23.   List various tree traversal techniques.
24.   Write the uses of sparse matrix.
25.   What are the different representations of tree in memory?
26.   List various sorting techniques.
27.   What is merge sort?
28.   Define ‘binary search’. Give an example.

PART-B

29.   (a) write a c program for insertion operation on a single-linked list. (b) explain double-linked circular list with an example.
30.   Explain the algorithm for conversion of infix to postfix expression with an example.
31.   (a) explain the implementation of queue using linked list. (b) write a short note on circular queue.
32.   Write a c program to perform traversal operations on tree.
33.   (a) explain linked representation of binary tree with an example. (b) explain binary search sort.
34.   Explain with a program for operations on binary tree for integers.
35.   (a) explain the principle of quick sort with an example. (b) write a c program for selection sort.
36.   (a) explain about abstract data types. (b) explain linear search technique with example.




Home                    Next(Oct/Nov-2012(c-09)


OCT/NOV-2012 (c-09)






C-09-CM-402
457
BOARD DIPLOMA EXAMINATION, (C-09)
OCT/NOV-2012
DCME-FOURTH SEMESTER EXAMINATION
Time: 3 hours]                   [Total Marks: 80
PART-A
Instructions: (1) Answer all questions
Each question carries three marks.
 Answers should be brief and straight to the point and shall not exceed five simple sentences.
1.       Define non-linear data structure and give an example.
2.       What is the time complexity?
3.       Write how the queue data structures are sued in computers.
4.       Define a linked list.
5.       What is a postfix expression? Give an example.
6.       What are the uses of a sparse matrix?
7.       Construct a binary tree from the inorder dbeac and the preorder abdec.
8.       List the operations that can be performed on a binary tree.
9.       Write how the merge sort works.
10.   What is searching? List the types of searching methods.
PART-B
Instructions: (1) Answer any five questions.
(2) Each question carries ten marks.
(3) Answers should be comprehensive and the criteria for valuation is the content but not the length of the answer
11.   (a) write how a node is inserted in a doubly linked list. (b) write how a node is deleted from a doubly linked list.
12.   Explain how to search and replace an element in a singly linked list.
13.   Write a program for implementing a circular queue using arrays.
14.   Explain the stack operations with example.
15.   Explain various tree traversal operations for the given example and write the outputs :


16.   Explain the representation of a binary tree using (a) arrays (b) linked lists.
17.   Explain the process of selection sort.
18.   (a) write a pseudo code bubble sorting. (b) write the algorithm for binary search.



Answers


PART-A
.
1.       Define non-linear data structure and give an example.
2.       What is the time complexity?
3.       Write how the queue data structures are sued in computers.
4.       Define a linked list.
5.       What is a postfix expression? Give an example.
6.       What are the uses of a sparse matrix?
7.       Construct a binary tree from the inorder dbeac and the preorder abdec.
8.       List the operations that can be performed on a binary tree.
9.       Write how the merge sort works.
10.   What is searching? List the types of searching methods.
PART-B
1.   (a) write how a node is inserted in a doubly linked list. (b) write how a node is deleted from a doubly linked list.
12.   Explain how to search and replace an element in a singly linked list.
13.   Write a program for implementing a circular queue using arrays.
14.   Explain the stack operations with example.
15.   Explain various tree traversal operations for the given example and write the outputs :

16.   Explain the representation of a binary tree using (a) arrays (b) linked lists.
17.   Explain the process of selection sort.
18.   (a) write a pseudo code bubble sorting. (b) write the algorithm for binary search.
















Monday, October 22, 2012

AVL TREES


//EX: 1C Program to insert and delete elements in an AVL Tree 1
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
#define FALSE 0
#define TRUE 1
struct AVLNode
{
  int data;
  int balfact;
  struct AVLNode *left;
  struct AVLNode *right;
};

struct AVLNode * insert(struct AVLNode *,int,int *);
struct AVLNode * deldata(struct AVLNode *,int,int *);
struct AVLNode * del(struct AVLNode *,struct AVLNode *,int *);
struct AVLNode * balr(struct AVLNode *,int *);
struct AVLNode * ball(struct AVLNode *,int *);
void display(struct AVLNode *);
void deltree(struct AVLNode *);
void main()
{
  struct AVLNode *avl=NULL;
  int h;
  clrscr();
  avl=insert(avl,20,&h);
  avl=insert(avl,6,&h);
  avl=insert(avl,29,&h);
  avl=insert(avl,5,&h);
  avl=insert(avl,12,&h);
  avl=insert(avl,25,&h);
  avl=insert(avl,32,&h);
  avl=insert(avl,10,&h);
  avl=insert(avl,15,&h);
  avl=insert(avl,27,&h);
 // avl=insert(avl,13,&h);
  printf("\n AVL Tree : \n");
  display(avl);
  avl=deldata(avl,5,&h);
  avl=deldata(avl,12,&h);
  printf("\n AVL tree after deletion of a node : \n");
  display(avl);
  deltree(avl);
  getch();

}



/* Inserts an element intp tree */
struct  AVLNode * insert(struct AVLNode *root,int data,int *h)
{
  struct AVLNode *node1,*node2;
  if(!root)
  {
     root=(struct AVLNode *)malloc(sizeof(struct AVLNode));
     root->data=data;
     root->left=NULL;
     root->right=NULL;
     root->balfact=0;
     *h=TRUE;
     return(root);
  }
  if(data < root->data)
  {
     root->left=insert(root->left,data,h);
     /* If left subtree is higher */
     if(*h)
     {
    switch(root->balfact)
    {
       case 1:
         node1=root->left;
         if(node1->balfact==1)
         {
           printf("\n Right Rotation alond %d. ",root->data);
           root->left=node1->right;
           node1->right=root;
           root->balfact=0;
           root=node1;
         }
         else
         {
          printf("\n Double rotation , left along %d",node1->data);
          node2=node1->right;
          node1->right=node2->left;

          printf(" then right along %d. \n",root->data);
          node2->left=node1;
          root->left=node2->right;
          node2->right=root;

          if(node2->balfact==1)
         root->balfact=-1;
          else
         root->balfact=0;
          if(node2->balfact==-1)
         node1->balfact=1;
          else
         node1->balfact=0;
          root=node2;
      }
      root->balfact=0;
      *h=FALSE;
      break;
       case 0:
         root->balfact=1;
         break;
       case -1:
         root->balfact=0;
         *h=FALSE;
      }
      }

  }

  if(data > root->data)
  {
    root->right=insert(root->right,data,h);
    /* If the right subtree is higher */
    if(*h)
    {
       switch(root->balfact)
       {
      case 1:
           root->balfact=0;
           *h=FALSE;
           break;
      case 0:
           root->balfact=-1;
           break;
      case -1:
           node1=root->right;
           if(node1->balfact==-1)
           {
          printf("\n Left rotation along %d. ",root->data);
          root->right=node1->left;
          node1->left=root;
          root->balfact=0;
          root=node1;
           }
           else
           {
          printf("\n Double rotation , right along %d",node1->data);
          node2=node1->left;
          node1->left=node2->right;
          node2->right=node1;
          printf(" then left along %d. \n",root->data);
          root->right=node2->left;
          node2->left=root;
          if(node2->balfact==-1)
             root->balfact=1;
          else
             root->balfact=0;
          if(node2->balfact==1)
             node1->balfact=-1;
          else
             node1->balfact=0;
          root=node2;
          }
          root->balfact=0;
          *h=FALSE;
    }
    }
 }
  return(root);

}


/* Deletes an item from the tree */
struct AVLNode * deldata(struct AVLNode *root,int data,int *h)
{
   struct AVLNode *node;
   if(!root)
   {
      printf("\n No such data. ");
      return (root);
   }
   else
   {
      if(data < root->data)
      {
     root->left=deldata(root->left,data,h);
     if(*h)
       root=balr(root,h);
      }
      else
      {
     if(data > root->data)
     {
        root->right=deldata(root->right,data,h);
          if(*h)
         root=ball(root,h);
     }
     else
     {
        node=root;
        if(node->right==NULL)
        {
           root=node->left;
           *h=TRUE;
           free(node);
        }
        else
        {
          node->right=del(node->right,node,h);
          if(*h)
         root=ball(root,h);
        }
      }
    }
      }

   return(root);
 }


 struct AVLNode * del(struct AVLNode *succ,struct AVLNode *node,int *h)
 {
    struct AVLNode *temp=succ;
    if(succ->left!=NULL)
    {
       succ->left=del(succ->left,node,h);
       if(*h)
      succ=balr(succ,h);
    }
    else
    {
       temp=succ;
       node->data=succ->data;
       succ=succ->right;
       free(temp);
       *h=TRUE;
    }
     return(succ);
}


/* Balance the tree , if right subtree is higher */
struct AVLNode * balr(struct AVLNode *root,int *h)
{
   struct AVLNode *node1,*node2;
   switch(root->balfact)
   {
     case 1:
    root->balfact=0;
    break;
     case 0:
    root->balfact=-1;
    *h=FALSE;
    break;
     case -1:
    node1=root->right;
    if(node1->balfact <= 0)
    {
      printf("\n Left rotation along %d. ",root->data);
      root->right=node1->left;
      node1->left=root;
      if(node1->balfact==0)
      {
          root->balfact=-1;
          node1->balfact=1;
        *h=FALSE;
      }
      else
      {
          root->balfact=node1->balfact=0;
      }
      root=node1;
    }
     else
     {
       printf("\n Double rotation , right along %d ",node1->data);
       node2=node1->left;
       node1->left=node2->right;
       node2->right=node1;
       printf(" then left along %d. \n",root->data);
       root->right=node2->left;
       node2->left=root;

       if(node2->balfact==-1)
      root->balfact=1;
       else
      root->balfact=0;
       if(node2->balfact==1)
     node1->balfact=-1;
       else
     node1->balfact=0;
       root=node2;
       node2->balfact=0;
    }
}
  return (root);
}


/* Balances the tree , if the left subtree is higher */
struct AVLNode * ball(struct AVLNode * root,int *h)
{
   struct AVLNode *node1,*node2;
   switch(root->balfact)
   {
      case -1:
     root->balfact=0;
     break;
      case 0:
     root->balfact=1;
     *h=FALSE;
     break;
      case 1:
     node1=root->left;
     if(node1->balfact >= 0)
     {
         printf("]n Right rotation along %d. ",root->data);
         root->left=node1->right;
         node1->right=root;
         if(node1->balfact==0)
         {
        root->balfact=1;
        node1->balfact=-1;
        *h=FALSE;
         }
         else
         {
           root->balfact=node1->balfact=0;
         }
         root=node1;
     }
     else
       {
      printf("\n Double rotation , left along %d ",node1->data);
      node2=node1->right;
      node1->right=node2->left;
      node2->left=node1;
      printf(" then right along %d .\n",root->data);

      root->left=node2->right;
      node2->right=root;

      if(node2->balfact==1)
          root->balfact=-1;
      else
          root->balfact=0;

      if(node2->balfact==-1)
          node1->balfact=1;
      else
          node1->balfact=0;
      root=node2;
      node2->balfact=0;
       }
    }
    return (root);
}




/*n Displays the tree in-order */
void display(struct AVLNode *root)
{
  if(root!=NULL)
  {
    display(root->left);
    printf("%d\t",root->data);
    display(root->right);
  }
}


/* Deletes the tree */
void deltree(struct AVLNode * root)
{
   if(root!=NULL)
   {
    deltree(root->left);
    deltree(root->right);
   }
   free(root);
}
//: CLICK HERE AVL TREES IN CPP

Monday, October 15, 2012

trees


/*Inorder Tree Traversal without Recursion
Using Stack is the obvious way to traverse tree without recursion. Below is an algorithm for traversing binary tree using stack. See this for step wise step execution of the algorithm.

1) Create an empty stack S.
2) Initialize current node as root
3) Push the current node to S and set current = current->left until current is NULL
4) If current is NULL and stack is not empty then
     a) Pop the top item from stack.
     b) Print the popped item, set current = current->right
     c) Go to step 3.
5) If current is NULL and stack is empty then we are done.
Let us consider the below tree for example

            1
          /   \
        2      3
      /  \
    4     5

Step 1 Creates an empty stack: S = NULL

Step 2 sets current as address of root: current -> 1

Step 3 Pushes the current node and set current = current->left until current is NULL
     current -> 1
     push 1: Stack S -> 1
     current -> 2
     push 2: Stack S -> 2, 1
     current -> 4
     push 4: Stack S -> 4, 2, 1
     current = NULL

Step 4 pops from S
     a) Pop 4: Stack S -> 2, 1
     b) print "4"
     c) current = NULL /*right of 4 */ and go to step 3
Since current is NULL step 3 doesn't do anything.

Step 4 pops again.
     a) Pop 2: Stack S -> 1
     b) print "2"
     c) current -> 5/*right of 2 */ and go to step 3

Step 3 pushes 5 to stack and makes current NULL
     Stack S -> 5, 1
     current = NULL

Step 4 pops from S
     a) Pop 5: Stack S -> 1
     b) print "5"
     c) current = NULL /*right of 5 */ and go to step 3
Since current is NULL step 3 doesn't do anything

Step 4 pops again.
     a) Pop 1: Stack S -> NULL
     b) print "1"
     c) current -> 3 /*right of 5 */

Step 3 pushes 3 to stack and makes current NULL
     Stack S -> 3
     current = NULL

Step 4 pops from S
     a) Pop 3: Stack S -> NULL
     b) print "3"
     c) current = NULL /*right of 3 */

Traversal is done now as stack S is empty and current is NULL.
Implementation:*/

#include<stdio.h>
#include<stdlib.h>
#define bool int

/* A binary tree tNode has data, pointer to left child
   and a pointer to right child */
struct tNode
{
   int data;
   struct tNode* left;
   struct tNode* right;
};

/* Structure of a stack node. Linked List implementation is used for
   stack. A stack node contains a pointer to tree node and a pointer to
   next stack node */
struct sNode
{
  struct tNode *t;
  struct sNode *next;
};

/* Stack related functions */
void push(struct sNode** top_ref, struct tNode *t);
struct tNode *pop(struct sNode** top_ref);
bool isEmpty(struct sNode *top);

/* Iterative function for inorder tree traversal */
void inOrder(struct tNode *root)
{
  /* set current to root of binary tree */
  struct tNode *current = root;
  struct sNode *s = NULL;  /* Initialize stack s */
  bool done = 0;

  while (!done)
  {
    /* Reach the left most tNode of the current tNode */
    if(current !=  NULL)
    {
      /* place pointer to a tree node on the stack before traversing
        the node's left subtree */
      push(&s, current);                                              
      current = current->left;
    }
       
    /* backtrack from the empty subtree and visit the tNode
       at the top of the stack; however, if the stack is empty,
      you are done */
    else                                                            
    {
      if (!isEmpty(s))
      {
        current = pop(&s);
        printf("%d ", current->data);

        /* we have visited the node and its left subtree.
          Now, it's right subtree's turn */
        current = current->right;
      }
      else
        done = 1;
    }
  } /* end of while */
}    

/* UTILITY FUNCTIONS */
/* Function to push an item to sNode*/
void push(struct sNode** top_ref, struct tNode *t)
{
  /* allocate tNode */
  struct sNode* new_tNode =
            (struct sNode*) malloc(sizeof(struct sNode));

  if(new_tNode == NULL)
  {
     printf("Stack Overflow \n");
     getchar();
     exit(0);
  }          

  /* put in the data  */
  new_tNode->t  = t;

  /* link the old list off the new tNode */
  new_tNode->next = (*top_ref);  

  /* move the head to point to the new tNode */
  (*top_ref)    = new_tNode;
}

/* The function returns true if stack is empty, otherwise false */
bool isEmpty(struct sNode *top)
{
   return (top == NULL)? 1 : 0;
}  

/* Function to pop an item from stack*/
struct tNode *pop(struct sNode** top_ref)
{
  struct tNode *res;
  struct sNode *top;

  /*If sNode is empty then error */
  if(isEmpty(*top_ref))
  {
     printf("Stack Underflow \n");
     getchar();
     exit(0);
  }
  else
  {
     top = *top_ref;
     res = top->t;
     *top_ref = top->next;
     free(top);
     return res;
  }
}

/* Helper function that allocates a new tNode with the
   given data and NULL left and right pointers. */
struct tNode* newtNode(int data)
{
  struct tNode* tNode = (struct tNode*)
                       malloc(sizeof(struct tNode));
  tNode->data = data;
  tNode->left = NULL;
  tNode->right = NULL;

  return(tNode);
}

/* Driver program to test above functions*/
int main()
{

  /* Constructed binary tree is
            1
          /   \
        2      3
      /  \
    4     5
  */
  struct tNode *root = newtNode(1);
  root->left        = newtNode(2);
  root->right       = newtNode(3);
  root->left->left  = newtNode(4);
  root->left->right = newtNode(5);

  inOrder(root);

  getchar();
  return 0;
}
//Time Complexity: O(n)

Sunday, June 17, 2012

Data Structures Record Questions


                                                 Record questions
1.       Wap to demonstrate the operations on singly linked list
2.       Wap to implement the stack using arrays
3.       Wap to implement the stack using switch case
4.       Wap to implement the queue using arrays
5.       Wap to implement the queue using switch case
6.       Wap to implement the bubble sort
7.       Wap to implement the selection sort
8.       Wap to implement the quick sort
9.       Wap to implement the merge sort
10.   Wap to implement the linear search
11.   Wap to implement the binary search
12.   Wap to demonstrate a sparse matrix
13.   Wap to transpose a sparse matrix
14.   Wap to implement the reverse of a single linked list
15.   Wap to implement the searching & sorting of a single linked list

Sunday, May 27, 2012

sorting programs and algorithms


/*Source code of simple quick sort implementation using array ascending order in c programming language*/
#include<stdio.h>
#include<conio.h>

void quicksort(int [10],int,int);

void main()
{
  int size,i;
  int a[]={5,9,7,2,4};
  n=5;
  clrscr();
/*  printf("Enter size of the array: ");
  scanf("%d",&n);

  printf("Enter %d elements: ",size);
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
  */
  quicksort(x,0,n-1);

  printf("Sorted elements: ");
  for(i=0;i<n;i++)
    printf(" %d",a[i]);
    getch();
}
void swap(int *x, int *y)
{
 int temp;
 temp=*x;
 *x=*y;
 *y=temp;
}

void quicksort(int x[10],int f,int l)
{
 int pivot,j,temp,i;
 if(f<last)
 {
   p=f;
   i=f;
   j=l;
   while(i<j)
   {
     while(x[i]<=x[p]&&i<l)
i++;
     while(x[j]>x[p])
j--;
     if(i<j)
     {
       swap(&x[i],&x[j]);
     }
    }//while
    swap(&x[p],&x[j]);
    quicksort(x,f,j-1);
    quicksort(x,j+1,l);
 }//if
}
/*
Output:
Enter size of the array: 5
Enter 5 elements: 3 8 0 1 2
Sorted elements: 0 1 2 3 8*/

Friday, May 25, 2012

Linked List


//WAP TO DEMONSTRATE THE OPERATIONS ON Single Linked List
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct sl_node
{
 int m;
 struct sl_node *link;
}*start=NULL;
typedef struct sl_node node;
void create()
{
 int n,i,marks;
 node *temp,*r;
 printf("enter the no of elements of linked list\n");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
  printf("enter the marks\n");
  scanf("%d",&marks);
  temp=(node*)malloc(sizeof(node));
  temp->m=marks;
  //temp=temp->link;
 //}
  if(start==NULL)
  {
   temp->link=NULL;
   start=temp;
  }
  else
  {
   r=start;
   while(r->link!=NULL)
   {
    r=r->link;
   }
    temp->link=r->link;
    r->link=temp;
  // }//while
  } //else
 }//create
 }
void addbeg(int marks)
{
  node* temp;
  temp=(node*)malloc(sizeof(node));
  temp->m=marks;
  temp->link=start;
  start=temp;
}
void addend(int marks)
{
 node *temp,*r;
 temp=start;
 while(temp->link!=NULL)
 {
  temp=temp->link;
  r=(node*)malloc(sizeof(node));
  r->m=marks;
  r->link=temp->link;
  temp->link=r;
 }
}
//add after specified node number
void addafter(int marks,int pos)
{
 int i;
 node* temp,*r;
 temp=start;
 for(i=1;i<pos;i++)
 temp=temp->link;
 r=(node*)malloc(sizeof(node));
 r->m=marks;
 r->link=temp->link;
 temp->link=r;
 }


void display()
{
 node *temp=start;
 if(temp==NULL)

  printf("it is empty\n");
 else
 {

  printf("sll follows\n");

  while(temp!=NULL)
  {
   printf("%d->",temp->m);
   temp=temp->link;
  }//while
 }//else
}//disp()
void del(int marks)
{
 node *temp,*old;
 temp=start;
 while(temp!=NULL)
 {
  if(temp->m==marks)
  {
   if(temp==start)
    start=start->link;
   else
    old->link=temp->link;
   printf("%d is deleted from s.l\n",marks);
   free(temp);
  }
  else
  {
   old=temp;
   temp=temp->link;
  } //else
 } //while
 printf("%d is not found in the s.l\n",marks);
}//del()
void destroy()
{
 node *temp;
 while(start!=NULL)
 {
  temp=start->link;
  free(start);
  start=temp;
 }
 printf("linked list is destroyed\n");
}
void menu()
{
 printf("1.insert at the begining of ll\n");
 printf("2.insert at the end\n");
 printf("3.displaying \n");
 printf("4.delete node\n");
 printf("5.destroy the s.l\n");
 printf("6.exit\n");
}
void main()
{
 int ch,pos,marks,c,count;
 node *start=NULL;
 void create();
 void addbeg(int);
// void addafter(int,int);
 void addend(int);
 void display();
 void del(int);
 void destroy();
 clrscr();
 create();
 menu();

 do
 {
  printf("enter ur choice\n");
  scanf("%d",&ch);
  switch(ch)
  {
   case 1:{
printf("enter the marks\n");
scanf("%d",&marks);
addbeg(marks);
break;
       }
   case 2:{
printf("enter the marks\n");
scanf("%d",&marks);
addend(marks);
break;
       }
/*   case 3:{
printf("enter the marks\n");
scanf("%d",&marks);
addafter(marks);
break;
       }
*/
    case 3:{
display();
break;
}
    case 4:{
printf("enter the marks\n");
scanf("%d",&marks);
del(marks);
break;
       }
    case 5:{
destroy();
break;
}
    default :
      exit();
  }//switch()

}while(ch!=6);
}


#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct ll
{
 int data;
 struct ll* link;
};
typedef struct ll node_type;

//creation of a linked list
node_type* sl_create()//this fun has no input but output first
{
 node_type *temp,*t,*k,*first;
 int x;
 first=(node_type*)malloc(sizeof(node_type));
 temp=first;
 printf("enter the data fields of all the nodes\n");
 while(scanf("%d",&x)!=EOF)
 //EOF MEANS CONTROL +Z
 {
  t=(node_type*)malloc(sizeof(node_type));
  t->data=x;//filing data field
  temp->link=t;
  temp=temp->link; //or t;//movin temp to latest node
 }
 temp->link=NULL;//fillin the link field of last node
 k=first;//put k pointer to dummy node to delete it by free
 first=first->link;//first come to action first node
 free(k);//
 return(first);
}
//displaying linked list
void ll_print(node_type *first)
{
 node_type *temp;
 for(temp=first;temp!=NULL;temp=temp->link)
 {
  printf("%d\t %u\n",temp->data,temp->link);//%u=address or position
 }
}


//concatination two linked lists
node_type* concatinate(node_type* first1,node_type* first2)
{
 node_type *temp;
 if((first1==NULL)&&(first2==NULL))
 {
  return(NULL);
 }
 else
 if((first1==NULL)&&(first2==NULL))
  return(first2);
 else if((first1!=NULL)&&(first2==NULL))
  return(first1);
 else
 { //putin a pointer temp &moving temp until temp link!=null
  for(temp=first1;temp->link!=NULL;temp=temp->link)
  {
   ;
  }
  temp->link=first2;
  return(first1);
 }
}

void main()
{
 node_type *first1,*first2,*first3;
 node_type* sl_create();
 node_type* concatinate(node_type* first1,node_type* first2);
 first1=sl_create();
 first2=sl_create();
 first3=concatinate(first1,first2);
 ll_print(first3);
}
*******************************************************************

//count a linked list
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct ll
{
 int data;
 struct ll* link;
};
typedef struct ll node_type;

//creation of a linked list
node_type* sl_create()//this fun has no input but output first
{
 node_type *temp,*t,*k,*first;
 int x;
 first=(node_type*)malloc(sizeof(node_type));
 temp=first;
 printf("enter the data fields of all the nodes\n");
 while(scanf("%d",&x)!=EOF)
 //EOF MEANS CONTROL +Z
 {
  t=(node_type*)malloc(sizeof(node_type));
  t->data=x;//filing data field
  temp->link=t;
  temp=temp->link; //or t;//movin temp to latest node
 }
 temp->link=NULL;//fillin the link field of last node
 k=first;//put k pointer to dummy node to delete it by free
 first=first->link;//first come to action first node
 free(k);//
 return(first);
}
//write a c function to find the no of nodes (ie. lenght of link.list
int count(node_type *first)
{
 node_type *temp;
 int ctr;
 ctr=0;
 for(temp=first;temp!=NULL;temp=temp->link)
 {
  ctr++;
 }
 return(ctr);
}


//displaying linked list
void ll_print(node_type *first)
{
 node_type *temp;
 for(temp=first;temp!=NULL;temp=temp->link)
 {
  printf("%d\t %u\n",temp->data,temp->link);//%u=address or position
 }
}


node_type * reverse(node_type *first)
{
 node_type *p,*q,*r;
 p=first;
 q=NULL;
 r=NULL;
 while(p!=NULL)
 {
  r=q;//a pointer moved one step right
  q=p;
  p=p->link;
  q->link=r;//addres of previous store NULL stored in r
   //bcoz of this only links are changed
 }
 first=q;
 return(first);
}

void main()
{
 node_type *first;
 node_type* sl_create();
 int ans,count();
 void ll_print();
 first=sl_create();//linked list created
 ans=count(first);
 printf("no of nodes is %d\n",ans);
}
 ll_print(first);//displaying
}
*********************************************************************************

//reversing a linked list
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct ll
{
 int data;
 struct ll* link;
};
typedef struct ll node_type;
//creation of a linked list
node_type* sl_create()//this fun has no input but output first
{
 node_type *temp,*t,*k,*first;
 int x;
 first=(node_type*)malloc(sizeof(node_type));
 temp=first;
 printf("enter the data fields of all the nodes\n");
 while(scanf("%d",&x)!=EOF)
 //EOF MEANS CONTROL +Z
 {
  t=(node_type*)malloc(sizeof(node_type));
  t->data=x;//filing data field
  temp->link=t;
  temp=temp->link; //or t;//movin temp to latest node
 }
 temp->link=NULL;//fillin the link field of last node
 k=first;//put k pointer to dummy node to delete it by free
 first=first->link;//first come to action first node
 free(k);//
 return(first);
}
//displaying linked list
void ll_print(node_type *first)
{
 node_type *temp;
 for(temp=first;temp!=NULL;temp=temp->link)
 {
  printf("%d\t %u\n",temp->data,temp->link);//%u=address or position
 }
}


node_type * reverse(node_type *first)
{
 node_type *p,*q,*r;
 p=first;
 q=NULL;
 r=NULL;
 while(p!=NULL)
 {
  r=q;//a pointer moved one step right
  q=p;
  p=p->link;
  q->link=r;//addres of previous store NULL stored in r
   //bcoz of this only links are changed
 }
 first=q;
 return(first);
}

void main()
{
 node_type *first,*reverse();
 node_type* sl_create();
 void ll_print();
 first=sl_create();//linked list created
 first=reverse(first);//function call
 ll_print(first);//displaying
}