Saturday, January 25, 2020

Posted on Leave a Comment

Online blood donors info system


Requirement of safe blood is increasing and regular voluntary blood donations are vital for blood transfusion services.  At present we have a blood donors clubs they arrange the required blood. But number of people registered with the clubs or blood banks are limited. So there is need for online site which serve the requirement of the recipient and the donor.
Online blood donors info system


Any member can join this website, Membership is free and open to all men and women between the ages of 18 to 60.  Once someone joins they will be grouped according to their blood type and will be issued with a membership card.  In case of a request for a certain blood group, members with that blood type will be requested to go to the hospital the patient is admitted in and donate blood.

This project will have the following modules

  • Register As Donor
  • Blood Donors
  • Hospitals
  • Blood Banks
  • Blood Facts
  • Blood Donation Process


Hardware and Software requirement

Hardware Requirement


Processor                     :       Intel Core Duo 2.0 GHz or more

RAM                            :       1 GB or More

Hard disk                      :       80 GB or more

Monitor                       :       15” CRT, or LCD monitor

Keyboard                    :       Normal or Multimedia

Mouse                         :       Compatible mouse

Software Requirement


Front End                :Visual Web Developer 2008 With Sql Server Compact Edition Or Visual Web Developer 2010 With Sql Server Compact Edition

Back End                 :MS Sql Server

Operation System     :Windows XP with server pack 3 Or Windows 7

Browser                   : Internet Explorer or Google Crome



Posted on Leave a Comment

Concatenation of two singly linked list

A ‘C’ program to create two singly linked lists and concatenate one list at the end of another list.

Concatenation of two singly linked list


Source code


#include 

#include 

#include 

#include 

#include 

struct linear_list {
  int info;
  struct linear_list * next;
}* start, * start1, * newnode, * ptr;

void main() {
  int item;
  int i;
  char ch;
  clrscr();
  printf(“\nCreate first linked list: \n”);
  newnode = (struct linear_list * ) malloc(sizeof(struct linear_list));
  start = newnode;
  do {
    printf(“\nEnter data: “);
    scanf(“ % d”, & item);
    newnode - > info = item;
    printf(“\nDo you want to create another node: (y / n)”);
    fflush(stdin);
    scanf(“ % c”, & ch);
    if (tolower(ch) == ’y’) {
      newnode - > next = (struct linear_list * ) malloc(sizeof(struct linear_list));
      newnode = newnode - > next;
    } else {
      newnode - > next = NULL;
    }
  } while (tolower(ch) != ’n’);
  clrscr();
  printf(“\nCreate second linked list: \n”);
  newnode = (struct linear_list * ) malloc(sizeof(struct linear_list));
  start1 = newnode;
  do {
    printf(“\nEnter data: “);
    scanf(“ % d”, & item);
    newnode - > info = item;
    printf(“\nDo you want to create another node: (y / n)”);
    fflush(stdin);
    scanf(“ % c”, & ch);
    if (tolower(ch) == ’y’) {
      newnode - > next = (struct linear_list * ) malloc(sizeof(struct linear_list));
      newnode = newnode - > next;
    } else {
      newnode - > next = NULL;
    }
  } while (tolower(ch) != ’n’);
  ptr = start;
  while (ptr - > next != NULL) {
    ptr = ptr - > next;
  }
  ptr - > next = start1;
  printf(“\n Concatenated Linked Lists are: \n”);
  ptr = start;
  i = 1;
  while (ptr != NULL) {
    printf(“\nNode % d: % d”, i, ptr - > info);
    ptr = ptr - > next;
    i++;
  }
  getch();
}

Output

Create first linked list:

Enter data: 2

Do you want to create another node:(y/n)y

Enter data: 8

Do you want to create another node:(y/n)y

Enter data: 10

Do you want to create another node:(y/n)n

Create second linked list:

Enter data: 5

Do you want to create another node:(y/n)y

Enter data: 7

Do you want to create another node:(y/n)y

Enter data: 34

Do you want to create another node:(y/n)n

Concatenated Linked Lists are:

Node 1 : 2
Node 2 : 8
Node 3 : 10
Node 4 : 5
Node 5 : 7
Node 6 : 34
Posted on Leave a Comment

Fibonacci series source code in C

Fibonacci series

Source code


#include

#include

void main() {
  int a, b, c, num, i;
  a = 0, b = 1, c = 0;
  clrscr();
  printf(“\nEnter the number till which u want the series::”);
  scanf(“ % d”, & num);
  printf(“\n”);

  for (i = 0; i < num; i++, c = a + b) {
    a = b;
    b = c;
    printf(“ % d\ t”, c);
  }
  getch();
}
Posted on Leave a Comment

Create two singly linked lists and perform the intersection operations

A ‘C’ program to create two singly linked lists and perform the intersection operations on two lists and display the resultant list.

Singly linked lists operations


Singly linked lists operations


#include

#include

/* Link list node */
struct node {
  int data;
  struct node * next;
};

/* A utility function to insert a node at the begining of a linked list*/
void push(struct node ** head_ref, int new_data);

/* A utilty function to chec if given data is present in a list */
int isPresent(struct node * head, int data);

/* Function to get union of two linked lists head1 and head2 */
/* Function to get intersection of two linked lists head1 and head2 */
struct node * getIntersection(struct node * head1, struct node * head2) {
  struct node * result = NULL;
  struct node * t1 = head1;

  // Traverse list1 and search each element of it in list2. If the element
  // is present in list 2, then insert the element to result
  while (t1 != NULL) {
    if (isPresent(head2, t1 - > data))
      push( & result, t1 - > data);
    t1 = t1 - > next;
  }

  return result;
}

/* A utility function to insert a node at the begining of a linked list*/
void push(struct node ** head_ref, int new_data) {
  /* allocate node */
  struct node * new_node =
    (struct node * ) malloc(sizeof(struct node));

  /* put in the data */
  new_node - > data = new_data;

  /* link the old list off the new node */
  new_node - > next = ( * head_ref);

  /* move the head to point to the new node */
  ( * head_ref) = new_node;
}

/* A utility function to print a linked list*/
void printList(struct node * node) {
  while (node != NULL) {
    printf(“ % d“, node - > data);
    node = node - > next;
  }
}

/* A utilty function that returns true if data is present in linked list
else return false */
int isPresent(struct node * head, int data) {
  struct node * t = head;
  while (t != NULL) {
    if (t - > data == data)
      return 1;
    t = t - > next;
  }
  return 0;
}
void main() {
  /* Start with the empty list */
  struct node * head1 = NULL;
  struct node * head2 = NULL;
  struct node * intersecn = NULL;
  int n, num, i;
  clrscr();
  /*create a linked lits 10->15->5->20 */
  printf(“\nEnter total number elements of first list: \n”);
  scanf(“ % d”, & n);
  for (i = 0; i < n; i++) {
    printf(“\nenter % d element: “, i + 1);
    scanf(“ % d”, & num);
    push( & head1, num);
  }

  printf(“\nEnter total number elements of second list: \n”);
  scanf(“ % d”, & n);
  for (i = 0; i < n; i++) {
    printf(“\nenter % d element: “, i + 1);
    scanf(“ % d”, & num);
    push( & head2, num);
  }

  intersecn = getIntersection(head1, head2);

  printf(“\n First list is\ n”);
  printList(head1);

  printf(“\n Second list is\ n”);
  printList(head2);

  printf(“\n Intersection list is\ n”);
  printList(intersecn);
  getch();
}

Output


Enter total number elements of first list :
5

enter 1 element : 3

enter 2 element : 6

enter 3 element : 9

enter 4 element : 12

enter 5 element : 16

Enter total number elements of second list :
3

enter 1 element : 3

enter 2 element : 6

enter 3 element : 10

First list is
16 12 9 6 3
Second list is
10 6 3
Intersection list is
3 6

Friday, January 24, 2020

Posted on Leave a Comment

Reverse of a linked list

Program to create a singly linked list, reverse it and display both the list.

Reverse of a linked list source code


#include 

// The list element type and head.

struct node {
  int data;
  struct node * link;
};
static struct node * first = NULL;

// A reverse function which uses only two extra pointers.

void reverse() {
  struct node * nxtNode, * curNode;

  // curNode traverses the list, first is reset to empty list.

  curNode = first;
  first = NULL;

  // Until no more in list, insert current before first and advance.

  while (curNode != NULL) {
    // Need to save next node since we’re changing the current.

    nxtNode = curNode - > link;

    // Insert at start of new list.

    curNode - > link = first;
    first = curNode;

    // Advance to next.

    curNode = nxtNode;
  }
}

// Code to dump the current list.

static void dumpNodes() {
  struct node * curNode = first;
  printf(“ === === === = \n”);
  while (curNode != NULL) {
    printf(“ % d\ n”, curNode - > data);
    curNode = curNode - > link;
  }
}

// Test harness main program.

void main() {
  int i, num, n;
  struct node * newnode;
  clrscr();
  // Create list (using actually the same insert-before-first
  // that is used in reverse function.
  printf(“\nEnter total number of nodes: \n”);
  scanf(“ % d”, & n);
  for (i = 0; i < n; i++) {
    newnode = (struct node * ) malloc(sizeof(struct node));
    printf(“\nenter data
      for % d node”, i + 1);
    scanf(“ % d”, & num);
    newnode - > data = num;
    newnode - > link = first;
    first = newnode;
  }

  // Dump list, reverse it, then dump again.
  printf(“\noriginal list is: \n”);
  dumpNodes();
  reverse();
  printf(“\nreversed list is: \n”);
  dumpNodes();
  getch();
}

Output


Enter total number of nodes :
4

enter data for 1 node4

enter data for 2 node9

enter data for 3 node3

enter data for 4 node2

original list is :
==========
2
3
9
4

reversed list is :
==========
4
9
3
2
Posted on Leave a Comment

Basic queue operations

Write menu driven program using ‘C’ for Static implementation of Queue. The menu  includes

–          Insert

–          Delete

–          Display

–          Exit

Basic queue operations


Queue operations source code

A queue is a particular kind of abstract data type or collection in which the entities in the collection are kept in order and the principal (or only) operations on the collection are the addition of entities to the rear terminal position and removal of entities from the front terminal position. This makes the queue a First-In-First-Out (FIFO) data structure. In a FIFO data structure, the first element added to the queue will be the first one to be removed. This is equivalent to the requirement that once an element is added, all elements that were added before have to be removed before the new element can be invoked.


#
define SIZE 5 /* Size of Queue */
int Q[SIZE], f = 0, r = -1; /* Global declarations */

Qinsert(int elem) {
  /* Function for Insert operation */
  if (Qfull()) printf(“\n\ n Overflow!!!!\n\ n”);
  else {
    ++r;
    Q[r] = elem;
  }
}

int Qdelete() {
  /* Function for Delete operation */
  int elem;
  if (Qempty()) {
    printf(“\n\ nUnderflow!!!!\n\ n”);
    return (-1);
  } else {
    elem = Q[f];
    f = f + 1;
    return (elem);
  }
}

int Qfull() {
  /* Function to Check Queue Full */
  if (r == SIZE - 1) return 1;
  return 0;
}

int Qempty() {
  /* Function to Check Queue Empty */
  if (f > r) return 1;
  return 0;
}

display() {
  /* Function to display status of Queue */
  int i;
  if (Qempty()) printf(”\n Empty Queue\ n”);
  else {
    printf(“Front - > ”);
    for (i = f; i <= r; i++)
      printf(“ % d“, Q[i]);
    printf(“ < -Rear”);
  }
}

main() {
  /* Main Program */
  int opn, elem;
  do {
    clrscr();
    printf(“\n### Queue Operations###\ n\ n”);
    printf(“\n Press 1 - Insert, 2 - Delete, 3 - Display, 4 - Exit\ n”);
    printf(“\n Your option ? “);
    scanf(“ % d”, & opn);
    switch (opn) {
    case 1:
      printf(“\n\ nRead the element to be Inserted ? ”);
      scanf(“ % d”, & elem);
      Qinsert(elem);
      break;
    case 2:
      elem = Qdelete();
      if (elem != -1)
        printf(“\n\ nDeleted Element is % d\ n”, elem);
      break;
    case 3:
      printf(“\n\ nStatus of Queue\ n\ n”);
      display();
      break;
    case 4:
      printf(“\n\ n Terminating\ n\ n”);
      break;
    default:
      printf(“\n\ nInvalid Option!!!Try Again!!\n\ n”);
      break;
    }
    printf(“\n\ n\ n\ n Press a Key to Continue...“);
    getch();
  } while (opn != 4);
}

Output


### Queue Operations ###
Press 1-Insert, 2-Delete,3-Display,4-Exit

Your option ?
1
Read the element to be Inserted ?3
Press a Key to Continue . . .
### Queue Operations ###
Press 1-Insert, 2-Delete,3-Display,4-Exit

Your option ? 1
Read the element to be Inserted ?6
Press a Key to Continue . . .
### Queue Operations ###
Press 1-Insert, 2-Delete,3-Display,4-Exit

Your option ? 1
Read the element to be Inserted ?9
Press a Key to Continue . . .



### Queue Operations ###
Press 1-Insert, 2-Delete,3-Display,4-Exit

Your option ? 3
Status of Queue

Front->3 6 9 <-rear .="" 1-insert="" 2-delete="" 2="" 3="" a="" continue="" deleted="" element="" front-="" is="" isplay="" key="" of="" operations="" option="" press="" queue="" status="" to="" xit="" your="">6 9 <-rear .="" a="" continue="" div="" key="" press="" to="">


Posted on Leave a Comment

Form binary search tree structure and display the nodes level wise

A ‘C’ program to read ‘n’ integers and store them in a Binary search tree structure and display the nodes level wise.

Form binary search tree structure

Binary search tree source code



#include 

typedef struct node {
  int value;
  struct node * right;
  struct node * left;
}
mynode;

mynode * root;

void add_node(int value);

void levelOrderTraversal(mynode * root);

void main() {
  int num;
  char ch = ’y’;
  clrscr();
  root = NULL;
  do {
    printf(“\nenter the node value”);
    scanf(“ % d”, & num);
    add_node(num);
    printf(“\ndo you want to
      continue (y / n)”);
    flushall();
    scanf(“ % c”, & ch);
  } while (ch != ’n’);
  printf(“\n\ n\ nLEVEL ORDER TRAVERSAL\ n\ n”);
  levelOrderTraversal(root);

  getch();
}

// Function to add a new node…
void add_node(int value) {
  mynode * prev, * cur, * temp;

  temp = (mynode * ) malloc(sizeof(mynode));
  temp - > value = value;
  temp - > right = NULL;
  temp - > left = NULL;

  if (root == NULL) {
    printf(“\nCreating the root..\n”);
    root = temp;
    return;
  }

  prev = NULL;
  cur = root;

  while (cur != NULL) {
    prev = cur;
    cur = (value < cur - > value) ? cur - > left : cur - > right;
  }

  if (value < prev - > value)
    prev - > left = temp;
  else
    prev - > right = temp;
}

// Level order traversal..
void levelOrderTraversal(mynode * root) {
  mynode * queue[100] = {
    (mynode * ) 0
  }; // Important to initialize!
  int size = 0;
  int queue_pointer = 0;

  while (root) {
    printf(“[ % d]“, root - > value);

    if (root - > left) {
      queue[size++] = root - > left;
    }

    if (root - > right) {
      queue[size++] = root - > right;
    }

    root = queue[queue_pointer++];
  }
}

Output


enter the node value5

Creating the root..

do you want to continue (y/n)y

enter the node value7

do you want to continue (y/n)y

enter the node value3

do you want to continue (y/n)y

enter the node value10

do you want to continue (y/n)y

enter the node value2

do you want to continue (y/n)n

LEVEL ORDER TRAVERSAL

[5] [3] [7] [2] [10]
Posted on Leave a Comment

Sorting elements of a singly linked list in ascending order

 A ‘C’ program to sort elements of a singly linked list in ascending order.

Sorting Elements Of A Singly Linked List


Sorting Singly list source code


#include
#include
#include

typedef struct NUM

{
  int data;
  struct NUM * link;
}
num;
num * createnode() {
  num * nn = NULL;
  nn = (num * ) malloc(sizeof(num));
  if (nn == NULL) {
    printf(“\n insufficient memory”);
    exit(0);
  } //end if
  return (nn);

} //end createnode

num * create() {
  num * hn = NULL, * cn = NULL, * nn = NULL;
  int i, n;
  printf(“\n enter no of node“);
  scanf(“ % d”, & n);
  printf(“\n enter data\ t”);
  for (i = 0; i < n; i++) {
    nn = createnode();
    scanf(“ % d”, & nn - > data);
    nn - > link = NULL;
    if (hn == NULL) {
      hn = nn;
      cn = nn;
    } //end if
    else {
      cn - > link = nn;
      cn = nn;
    }
  } //end for
  return (hn);
} //end create
void display(num * hn) {
  num * cn = NULL;
  num * temp, * j, * i;
  printf(“\n original data present in link list is“);
  for (cn = hn; cn != NULL; cn = cn - > link) {
    printf(” % d”, cn - > data);
  } //end for
  /*following code counts the nonzero,even,odd*/
  for (j = hn; j - > link != NULL; j = j - > link) {
    for (i = hn; i - > link != NULL; i = i - > link) {
      if (i - > data > i - > link - > data) {
        temp - > data = i - > data;
        i - > data = i - > link - > data;
        i - > link - > data = temp - > data;

      }
    }
  }
  printf(“\n data in ascending order is“);
  for (cn = hn; cn != NULL; cn = cn - > link) {
    printf(” % d”, cn - > data);
  }
} //end display
void main() {
  num * hn, * nn, * pn;
  int ch;
  clrscr();
  hn = create();
  display(hn);

  getch();
} //end main

Output


enter no of node 5
enter data 4 7 2 1 9
original data present in link list is 4 7 2 1 9
data in ascending order is 1 2 4 7 9
Posted on Leave a Comment

Sorting records of ‘n’ employees on key employee-number using insertion sort method

A ‘C’ program to sort the records of ‘n’ employees on key employee-number using insertion sort method.

Insertion Sort Method


Insertion Sort Source code



#include

#include

typedef struct employee {
  char name[20];
  int empid, salary;
}
emp;

void display(emp m[20], int n) {
  int i;
  printf(“\nEMPLOYEE ID\ tNAME\ tSALARY”);
  for (i = 0; i < n; i++) {
    printf(“\n % d\ t\ t % s\ t\ t % d”, m[i].empid, m[i].name, m[i].salary);
  }
}

void insertion(emp m[20], int n) {
  int i, j;
  emp temp;
  for (i = 1; i < n; i++) {
    j = i - 1;
    temp = m[i];
    while (strcmp(m[j].empid, temp.empid) < 0 && j >= 0) {
      m[j + 1] = m[j];
      j–;

    }
    m[j + 1] = temp;
    // display(m,n);
  }
  display(m, n);

}
void main() {
  emp m[20];
  int n, i, ch;
  clrscr();
  printf(“\nenter the limit: ”);
  scanf(“ % d”, & n);
  printf(“\ngive employee id, name and salary: ”);
  for (i = 0; i < n; i++) {
    scanf(“ % d % s % d”, & m[i].empid, m[i].name, & m[i].salary);
  }
  display(m, n);
  insertion(m, n);
  getch();
}


Output

enter the limit:2

give employee id,name and salary:102 shilpa 700
100 priti 900

EMPLOYEE ID NAME SALARY
102 shilpa 700
100 priti 900

EMPLOYEE ID NAME SALARY
100 priti 900
102 shilpa 700
Posted on Leave a Comment

Count all non-zero, odd and even numbers in the singly linked list


A ‘C’ program to count all non-zero elements, odd numbers and even numbers in the singly linked list.

Odd And Even Numbers In The Singly Linked List

Singly linked list Source Code 


#include

#include

typedef struct NUM

{
  int data;
  struct NUM * link;

}
num;

num * createnode() {
  num * nn = NULL;
  nn = (num * ) malloc(sizeof(num));
  if (nn == NULL) {
    printf(“\n insufficient memory”);
    exit(0);
  } //end if
  return (nn);

} //end createnode

num * create() {
  num * hn = NULL, * cn = NULL, * nn = NULL;
  int i, n;
  printf(“\n enter no of node“);
  scanf(“ % d”, & n);
  printf(“\n enter data\ t”);
  for (i = 0; i < n; i++) {
    nn = createnode();
    scanf(“ % d”, & nn - > data);
    nn - > link = NULL;
    if (hn == NULL) {
      hn = nn;
      cn = nn;
    } //end if
    else {
      cn - > link = nn;
      cn = nn;
    }
  } //end for
  return (hn);
} //end create
void display(num * hn) {
  num * cn = NULL;
  int cnt_nonzero = 0, cnt_even = 0, cnt_odd = 0;
  num * temp = NULL;
  printf(“\n data present in link list is“);
  for (cn = hn; cn != NULL; cn = cn - > link) {
    printf(” % d”, cn - > data);
  } //end for
  /*following code counts the nonzero,even,odd*/
  temp = hn;
  while (temp != NULL) {
    if (temp - > data != 0) {
      cnt_nonzero++;
    }
    if (temp - > data != 0) {
      if ((temp - > data) % 2 == 0) {

        cnt_even++;
      }
      if ((temp - > data) % 2 != 0) {
        cnt_odd++;
      }
    }

    temp = temp - > link;
  }

  printf(“\nThe number of non - zero elements is % d”, cnt_nonzero);
  printf(“\nThe number of even elements is % d”, cnt_even);
  printf(“\nThe number of odd elements is % d”, cnt_odd);
} //end display
void main() {
  num * hn, * nn, * pn;
  int ch;
  clrscr();
  hn = create();
  display(hn);

  getch();
} //end main


Output


enter no of node 5
enter data 0 1 0 2 3
data present in link list is 0 1 0 2 3
The number of non-zero elements is 3
The number of even elements is 1
The number of odd elements is 2

Posted on Leave a Comment

Static implementation of circular queue for characters

Write a menu driven program using ‘C’ for static implementation of Circular Queue for characters. The menu includes



 – Insert

 – Delete

 – Display

 – Exit


Source Code

#include
#define max 5
int front, rear;
char q[max];
void enqueue(void);
void dequeue(void);
void qdisplay(void);
void main(void) {
  int c;
  clrscr();
  front = rear = -1;
  do {
    printf(“1: insert\ n2: deletion\ n3: display\ n4: exit\ nenter choice: ”);
    scanf(“ % d”, & c);
    switch (c) {
    case 1:
      enqueue();
      break;
    case 2:
      dequeue();
      break;
    case 3:
      qdisplay();
      break;
    case 4:
      printf(“pgm ends\ n”);
      break;
    default:
      printf(“wrong choice\ n”);
      break;
    }
  } while (c != 4);
  getch();
}
void enqueue(void) {
  char x;
  if ((front == 0 && rear == max - 1) || (front == rear + 1)) //condition for full Queue
  {
    printf(“Queue is overflow\ n”);
    return;
  }
  if (front == -1) {
    front = rear = 0;
  } else {
    if (rear == max - 1) {
      rear = 0;
    } else {
      rear++;
    }
  }
  printf(“enter the character\ n”);
  flushall();
  scanf(“ % c”, & x);
  q[rear] = x;
  printf(” % c succ.inserted\ n”, x);
  return;
}
void dequeue(void) {
  char y;
  if (front == -1) {
    printf(“q is underflow\ n”);
    return;
  }
  y = q[front];
  if (front == rear) {
    front = rear = -1;
  } else {
    if (front == max - 1) {
      front = 0;
    } else {
      front++;
    }
  }
  printf(“ % c succ.deleted\ n”, y);
  return;
}
void qdisplay(void) {
  int i, j;
  if (front == rear == -1) {
    printf(“q is empty\ n”);
    return;
  }
  printf(“elements are: \n”);
  for (i = front; i != rear; i = (i + 1) % max) {
    printf(“ % c\ n”, q[i]);

  }

  printf(“ % c\ n”, q[rear]);
  return;
}



OUTPUT:


1:insert

2:deletion

3:display

4:exit

enter choice:1

enter the no:

a

a succ. inserted

1:insert

2:deletion

3:display

4:exit

enter choice:1

enter the no:

b

b succ. inserted

1:insert

2:deletion

3:display

4:exit

enter choice:1

enter the no:

c

c succ. inserted

1:insert

2:deletion

3:display

4:exit

enter choice:3

elements are :

a

b

c

1:insert

2:deletion

3:display

4:exit

enter choice:2

a succ. deleted

1:insert

2:deletion

3:display

4:exit

enter choice:3

elements are :

b

c

1:insert

2:deletion

3:display

4:exit

enter choice:4


Posted on Leave a Comment

Swap mth and nth element of singly linked list

A ‘C’ program to swap mth and nth element of singly linked list.

Swap Mth And Nth Element Of Singly Linked List


Source Code



#include<stdio.h>

#include<conio.h>

struct link {

  int data;

  struct link * next;

}; /*End of struct link*/

struct link * start = NULL;

void create();

void display();

void swap();

void main() {

  int ch;

  clrscr();

  do {

    printf(“\nPress 1 To Create Node.”);

    printf(“\nPress 2 To Display”);

    printf(“\nPress 3 To Swap”);

    printf(“\nPress 4 To Exit”);

    printf(“\nEnter Your Choice: “);

    scanf(“ % d”, & ch);

    switch (ch) {

    case 1:

      create();

      break;

    case 2:

      display();

      break;

    case 3:

      swap();

      break;

    case 4:

      exit(0);

    default:

      printf(“\nInvalid Choice… Try Again”);

      getch();

    } /*End of switch*/

  } while (ch != 4); /*End of while loop*/

} /*End of void main()*/

void create() {

  struct link * p, * node;

  printf(“\nEnter Data: “);

  p = (struct link * ) malloc(sizeof(struct link));

  scanf(“ % d”, & p - > data);

  p - > next = NULL;

  if (start == NULL)

    start = p;

  else {

    node = start;

    while (node - > next != NULL)

      node = node - > next;

    node - > next = p;

  } /*End of else*/

} /*End of void create()*/

void display() {

  struct link * node;

  if (start == NULL) {

    printf(“\nList Is Empty”);

    getch();



  } /*End of if*/

  node = start;

  while (node != NULL) {

    printf(“ % d“, node - > data);

    node = node - > next;

  } /*End of while loop*/

  getch();

} /*End of void display()*/

void swap() {

  int m, n, i;

  struct link * node1, * node2;

  if (start == NULL) {

    printf(“\nList Is Empty”);

  } /*End of if*/

  node1 = start;

  printf(“\nEnter Mth Position: “);

  scanf(“ % d”, & m);

  for (i = 0; i < m; i++) {

    node1 = node1 - > next;

    if (node1 == NULL) {

      printf(“\nWrong Location Enterred, , ”);

    } /*End of if*/

  } /*End of i for loop*/

  printf(“\nEnter Nth Position: “);

  scanf(“ % d”, & n);

  node2 = start;

  for (i = 0; i < n; i++) {

    node2 = node2 - > next;

    if (node2 == NULL) {

      printf(“\nWrong Location Enterred..”);

    } /*End of if*/

  } /*End of i for loop*/

  node1 - > data = (node1 - > data) + (node2 - > data) - ((node2 - > data) = (node1 - > data));

  printf(“\nElement Swapped”);

}

OUTPUT:



Press 1 To Create Node.
Press 2 To Display
Press 3 To Swap
Press 4 To Exit
Enter Your Choice: 1
Enter Data: 3
Press 1 To Create Node.
Press 2 To Display
Press 3 To Swap
Press 4 To Exit
Enter Your Choice: 1
Enter Data: 5
Press 1 To Create Node.
Press 2 To Display
Press 3 To Swap
Press 4 To Exit
Enter Your Choice: 1
Enter Data: 9
Press 1 To Create Node.
Press 2 To Display
Press 3 To Swap
Press 4 To Exit
Enter Your Choice: 2
3 5 9
Press 1 To Create Node.
Press 2 To Display
Press 3 To Swap
Press 4 To Exit
Enter Your Choice: 3
Enter Mth Position: 0
Enter Nth Position: 1
Element Swapped
Press 1 To Create Node.
Press 2 To Display
Press 3 To Swap
Press 4 To Exit
Enter Your Choice: 2
5 3 9

  Download Source Code
Download Source code
Posted on Leave a Comment

Dynamic queue linked list of characters

Write a menu driven program using ‘C’ for Dynamic implementation of Queue for characters. The menu includes

– Insert
– Delete
– Display
– Exit


Dynamic Queue Linked List

Dynamic queue linked list Source Code


/*program for dynamic implementation of queue of characters */ #include

#include

struct node {
  char info;
  struct node * next;
}* front, * rear;
void enqueue(char elt);
int dequeue();
void display();

void main() {
  int ch;
  char elt;
  clrscr();
  rear = NULL;
  front = NULL;
  do {
    printf("\n ** ** ** ** ** ** Menu ** ** ** ** ** ** ** * ");
    printf("\nEnter: \n1 - > Insert\ n2 - > Delete\ n3 - > Display\ n4 - > Exit\ n");
    printf("Enter your choice::");
    scanf(" % d", & ch);
    switch (ch) {
    case 1:
      printf("Enter The character\ n");
      flushall();
      scanf(" % c", & elt);
      enqueue(elt);
      break;
    case 2:
      elt = dequeue();
      printf("The deleted element = % c\ n", elt);
      break;
    case 3:
      display();
      break;
    default:
      printf("~~~Exit~~~");
      getch();
      exit(0);
      break;
    }
  } while (ch != 4);
}
void enqueue(char elt) {
  struct node * p;
  p = (struct node * ) malloc(sizeof(struct node));
  p - > info = elt;
  p - > next = NULL;
  if (rear == NULL || front == NULL)
    front = p;
  else
    rear - > next = p;
  rear = p;
}
int dequeue() {
  struct node * p;
  int elt;
  if (front == NULL || rear == NULL) {
    printf("\nUnder Flow");
    getch();
    exit(0);
  } else {
    p = front;
    elt = p - > info;
    front = front - > next;
    free(p);
  }
  return (elt);
}
void display() {
  struct node * t;
  t = front;
  while (front == NULL || rear == NULL) {
    printf("\nQueue is empty");
    getch();
    exit(0);
  }
  while (t != NULL) {
    printf("- > % c", t - > info);
    t = t - > next;
  }
}

Dynamic queue linked list OUTPUT


************ Menu ***************
Enter:
1->Insert
2->Delete
3->Display
4->Exit
Enter your choice :: 1
Enter The character
a
************ Menu ***************
Enter:
1->Insert
2->Delete
3->Display
4->Exit
Enter your choice :: 1
Enter The character
b
************ Menu ***************
Enter:
1->Insert
2->Delete
3->Display
4->Exit
Enter your choice :: 1
Enter The character
c
************ Menu ***************
Enter:
1->Insert
2->Delete
3->Display
4->Exit
Enter your choice :: 3
->a->b->c
************ Menu ***************
Enter:
1->Insert
2->Delete
3->Display
4->Exit
Enter your choice :: 2
The deleted element = a
************ Menu ***************
Enter:
1->Insert
2->Delete
3->Display
4->Exit
Enter your choice :: 3
->b->c
************ Menu ***************
Enter:
1->Insert
2->Delete
3->Display
4->Exit
Enter your choice ::4

Download Source Code

Download Source code


Codearea.in is featured by projectsgeek.com. Powered by Blogger.