Skip to main content

Posts

Write a C Program that uses functions to perform the following operations on a single linked list Creation, Insertion, Deletion, Traversal

  #include <stdio.h> #include <stdlib.h>   struct node {   int data;   struct node *next; };   struct node *start = NULL; void insert_at_begin(int); void insert_at_end(int); void traverse(); void delete_from_begin(); void delete_from_end(); int count = 0;   int main () {   int i, data;     for (;;) {     printf("1. Insert an element at the beginning of linked list.\n");     printf("2. Insert an element at the end of linked list.\n");     printf("3. Traverse linked list.\n");     printf("4. Delete an element from beginning.\n");     printf("5. Delete an element from end.\n");     printf("6. Exit\n");       scanf("%d", &i);       if (i == 1) {       printf("Enter value of element\n");       ...

Write a C Program to create a queue and perform Push, Pop, Traversal

  #include <stdio.h> #include <stdlib.h>   void push1(int); void push2(int); int pop1(); int pop2(); void enqueue(); void dequeue(); void display(); void create();   int st1[100], st2[100]; int top1 = -1, top2 = -1; int count = 0;   void main() {     int ch;     printf("\Piyush \n 315/CSE/2019");     printf("\n1 - Enqueue element into queue");     printf("\n2 - Dequeu element from queue");     printf("\n3 - Display from queue");     printf("\n4 - Exit");     create();     while (1)     {         printf("\nEnter choice");         scanf("%d", &ch);         switch (ch)         {         ca...

Write a C Program that uses Stack Operations to perform the Evaluating the postfix expression

  #include <stdio.h> #include <conio.h> #include <ctype.h> #define SIZE 50 char s[SIZE]; int top=-1; push(char elem) {     s[++top]=elem; } char pop() {     return(s[top--]); } int pr(char elem) {     switch(elem)     {     case '#': return 0;     case '(': return 1;     case '+':     case '-': return 2;     case '*':     case '/': return 3;     } } void main() {     char infx[50],pofx[50],ch,elem;     int i=0,k=0;     printf("\n\nRead the Infix Expression ? ");     scanf("%s",infx);     push('#');     while( (ch=infx[i++]) != '\0')     {     if( ch == '(') push(ch);     else     if(isalnum(ch)) pofx[k++]=ch;       else     if( ch == ')')     {         while( s[top] != '(')       pofx[k++]...

Write a C Program that uses Stack Operations to perform the Converting an infix expression into postfix expression

  #include <stdio.h> #include <conio.h> #include <ctype.h> #define SIZE 50 char s[SIZE]; int top=-1; push(char elem) {     s[++top]=elem; }   char pop() {     return(s[top--]); }   int pr(char elem) {     switch(elem)     {     case '#': return 0;     case '(': return 1;     case '+':     case '-': return 2;     case '*':     case '/': return 3;     } }   void main() {     char infx[50],pofx[50],ch,elem;     int i=0,k=0;       printf("\n\nRead the Infix Expression ? ");     scanf("%s",infx);     push('#');     while( (ch=infx[i++]) != '\0')     {     if( ch == '(') push(ch);  ...

Write a C Program to create a stack using an array and perform Push operation , Pop operation

  #include <stdio.h>           #define MAX 50   void insert(); void delete(); void display(); int queue_array[MAX]; int rear = - 1; int front = - 1; main() {     int choice;     while (1)     {         printf("1.Insert element to queue \n");         printf("2.Delete element from queue \n");         printf("3.Display all elements of queue \n");         printf("4.Quit \n");         printf("Enter your choice : ");         scanf("%d", &choice);         switch (choice)         {             case 1:  ...

C Programs on Binary Search

  #include <stdio.h>   void main() {     int array[10];     int i, j, num, temp, keynum;     int low, mid, high;     printf("Enter the value of num \n");     scanf("%d", &num);     printf("Enter the elements one by one \n");     for (i = 0; i < num; i++)     {         scanf("%d", &array[i]);     }     printf("Input array elements \n");     for (i = 0; i < num; i++)     {         printf("%d\n", array[i]);     }     /*   Bubble sorting begins */     for (i = 0; i < num; i++)     {         for (j = 0; j < (num - i - 1); j++)       ...

C Programs on Sequential Search

  #include <stdio.h>   void main() {  int num;       int i,  keynum, found = 0;       printf("Enter the number of elements ");     scanf("%d", &num);     int array[num];     printf("Enter the elements one by one \n");     for (i = 0; i < num; i++)     {         scanf("%d", &array[i]);     }       printf("Enter the element to be searched ");     scanf("%d", &keynum);     /*  Linear search begins */     for (i = 0; i < num ; i++)     {         if (keynum == array[i] )         {             found = 1;             break; ...