Posts

Showing posts from September, 2020

IMPLEMENTATION OF QUEUE BY LINKEDLIST : C PROGRAM

Image
  Hey there ,welcome to yocoding. Here is the code for queue by linked list in C programming language. Program code : #include<stdio.h> #include <stdlib.h> struct node {     int data;     struct node *next; }; struct node *rear=NULL,*front=NULL; void enque(int d) {     struct node *p;     p=(struct node *)malloc(sizeof(struct node));     p->data=d;     if(front==NULL)     {         p->next=NULL;         front=p;         rear=p;         return;     }     rear->next=p;     p->next=NULL;     rear=p;     return; } void deque() {     struct node *temp;     if(front==NULL)         printf("queue is empty.\n");     else if(front==rear){         printf("deleted element %d.\n",front->data);         free(front);         front=NULL;     }     else{         printf("deleted element %d.\n",front->data);         temp=front;         front=front->next;         free(temp);     }     return; } void display() {     struct node *temp=front;    

IMPLEMENTATION OF QUEUE BY ARRAY : C PROGRAM

Image
  Here is the C program for implementation of queue using array.  Queue is a data structure.  program code : #include<stdio.h> #include<stdlib.h> int que[6],f=-1;r=-1; void enque(int d) {     if(f==5)     {         printf("queue is full,enque not possible.\n");         return;     }     if(f==-1)     {         f=r=0;         que[r]=d;     }     else{         r++;         que[r]=d;     } } void deque() {     if(f==-1){         printf("list is empty,deletion not possible\n");         return;     }     if(f==r){         printf("deleted element is %d\n",que[r]);         f=r=-1;     }     else{         printf("deleted element is %d\n.",que[f]);         f++;         return;     } } void display() {     int i;     if(f==-1){         printf("queue is empty.\n");         return;     }     printf("queue elements are : ");     for(i=f;i<=r;i++)         printf("%d ",que[i]);     printf("\n"); } int main(

Implementation of Stack with Singly Linked List : C Program

Image
  Here is the code for implementation of stack with singly linked list : program code : #include<stdio.h> #include <stdlib.h> struct node {     int data;     struct node *next; }; struct node *top=NULL; void push(int d) {     struct node *newnode=(struct node*)malloc(sizeof(struct node));     newnode->data=d;     newnode->next=NULL;     if(top==NULL)     {         top=newnode;     }     else{         newnode->next=top;         top=newnode;     }     printf("\ndata %d has been pushed (entered to stack).",d); } void pop() {     struct node *p,*temp=top;     if(temp=NULL)     {         printf("\nstack is empty.");         return;     }     p=top;     top=top->next;     free(p);     printf("\ntop element has been poped(deleted)."); } void display() {     struct node *p=top;     if(p==NULL)     {         printf("\nstack is empty.");         return;     }     printf("\nstack elements are : ");     while(p!= NULL)     {

Basic C++ class and object program

Image
  This is a basic program of class and object C++ : program : #include <iostream> using namespace std; class age {     int age;     char name[2]; public:     void get()     {         cout<<"enter your age and name: ";         cin>>age>>name;     }     void dis()     {         cout<<"name is "<<name<<",age is "<<age;     } }; int main() {     age a1;     a1.get();     a1.dis();     return 0; } output :

swapping first and last digits of a number :Python Program

Image
  Here is the program for swapping first and last digits of a number in Python programming language program code : n=int(input("number:")) last=n%10 n=int(n/10) n1=str(n) n2=str(1) n6=str(1) for i in range(len(n1)-1):     n2=n2+str(0)     n6=n6+str(0) n6=int(n6) n2=int(n2) n5=int(n/n6) n3=n%n2 print(n5) n4=str(last)+str(n3)+str(n5) print(int(n4)) output : enter number :284517 784512 happy coding. comment what you need.

stack using array : C program

Image
  Here is the implementation of Stack using Array in C : Program code: #include <stdio.h> #define size 10 int stack[size]; int top=-1; void push(int x) {     if(top>=size)     {         printf("\noverflow");     }     else     {         top++;         stack[top]=x;     } } void pop() {     if(top<=0)     {         printf("\nstack is empty.");         return;     }     return stack[top--]; } void display() {     int i;     if(top<0)     {         printf("\nstack is empty");         return;     }     printf("\nstack elements are : ");     for(i=top;i>=0;i--)     {         printf("%d ",stack[i]);     }     printf("\n"); } int main() {     int op,el,exit=1;     do     {         printf("what action you want to take :\n");         printf("1.push   2.pop   3.display   4.topvalueandsize   5.exit\n");         scanf("%d",&op);         switch(op)         {         case 1:             pr

Singly Linked list C program :create insertion deletion search display

Image
C Program 👇 #include <stdio.h> #include <stdlib.h> struct node {     int data;     struct node *next; }; struct node *head,*p=NULL; void create(int d) {     struct node *newnode=(struct node*)malloc(sizeof(struct node));     newnode->data=d;     newnode->next=NULL;     if(head==NULL)     {         head=newnode;         p=newnode;     }     else     {         p->next=newnode;         p=newnode;     } } void display() {     struct node *temp=head;     if (head==NULL)     {         printf("the list is empty");         return;     }     printf("the list elements are : \n");     while(temp!=NULL)     {         printf("%d ",temp->data);         temp=temp->next;     }     printf("\n"); } void inp(int pos,int d) {     struct node *ptr,*p=head;     int i;     ptr=(struct node *)malloc(sizeof(struct node));     ptr->data=d;     if(pos==1)     {         ptr->next=p;         head=ptr;     }     else     {     for(i=1;i<po