Tuesday, January 31, 2023

All PHP Solved Slips

 Q1)          Write a PHP script for the following: Design a form to accept a string. Write a function to count the total number of vowels (a,e,i,o,u) from the string. Show  the occurrences of each vowel from the string.Check whether the given string is a palindrome or not, without using built-in function.(Use radio buttons and the concept of function.Use‘include’construct or require stmt.)


1.Create Slip1.php File
<?php
function cnt_vowels($a,$l)
{
    $v_cnt = 0;
for($i=0;$i<$l;$i++)
{
if(($a[$i]=='a')||($a[$i]=='e')||($a[$i]=='i')||($a[$i]=='o')||
($a[$i]=='u')||($a[$i]=='A')||($a[$i]=='E')||($a[$i]=='I')||
($a[$i]=='O')||($a[$i]=='U'))$v_cnt++;
}
return $v_cnt;
}

function occured_vowelsinstring($a,$l)
{
$av=0;
$ev=0;
$iv=0;
$ov=0;
$uv=0;
$cnt=0;
    for ($i = 0; $i < $l; $i++) {
        if (($a[$i] == 'a') || ($a[$i] == 'A'))
        {
            $av++;
        }
        elseif (($a[$i] == 'e') || ($a[$i] == 'E'))
        {
            $ev++;
        }
        elseif (($a[$i] == 'i') || ($a[$i] == 'I'))
        {
            $iv++;
        }
        elseif (($a[$i] == 'o') || ($a[$i] == 'O'))
        {
            $ov++;
        }
        elseif (($a[$i] == 'u') || ($a[$i] == 'U'))
        {
            $uv++;
        }
        else
        {
            $cnt++;
        }
    }
echo"<br>Total'a':$av";
echo"<br>Total'e':$ev";
echo"<br>Total'i':$iv";
echo"<br>Total'o':$ov";
echo"<br>Total'u':$uv";
echo"<br>Total Count Without Vowels:$cnt";
$tot=$av+$ev+$iv+$ov+$uv;
return $tot;
}
$str=$_POST['str'];
$op=$_POST['op'];
$l=strlen($str);

switch($op)
{
case 1:
echo"String is=$str<br>";
$v_cnt=cnt_vowels($str,$l);
echo"Total vowels Present in string are =$v_cnt<br>";
exit(0);

case 2:
echo"string is=$str<br>";
$v_occ=occured_vowelsinstring($str,$l);
echo"<br>Total Vowels Present in String are=$v_occ<br>";
exit(0);
}

$str1=strrev($str);
$a=strlen($str);
$f=0;
for($j=0;$j<$a;$j++)
{
    if($str1[$j]==$str[$j])
{
$f=0;
}
else
{
$f=1;
break;
}
}
if($f==0)
{
echo"String is Palindrome";
}
else
{
echo"String is Not Palindrome";
}
?>

2.Create slips.html
<html>
<body>
<form action="slip1.php" method="post">
<h3>Enter String:<input type="text"name="str" maxlength="20"></h3>
<input type="radio"name="op"value="1">Count of Total Vowels in String<br>
<input type="radio"name="op"value="2">Occurances of each vowel in string<br>
<input type="radio"name="op"value="3">Check Given String is Palindrome or Not<br><br>
<input type="submit"value="Click to See Output">
</form>
</body>
</html>

Sunday, January 29, 2023

Doubly Linked List Insertion

 Hello Friends,

Today we discuss about Doubly Linked List Insertion Functions:

Function for insert at first Position or Insert at Beginning:

void insert_beg()
    {
        newnode=(struct node *)malloc(sizeof(struct node));
        printf("\nEnter data:");
        scanf("%d",&newnode->data);
        newnode->next=head;
        newnode->prev=NULL;
        head->prev=newnode;
        head=newnode;
    }

Function for Insert at Specific Position or Insert In between:

void insert_spec()
    {
        struct node *a=head,*b=head;
        int i,j,pos;
        printf("\nEnter Position where you want to add NewNode:");
        scanf("%d",&pos);
        for(i=1; i<pos-1; i++)
        {a=a->next;
        }
        newnode=(struct node *)malloc(sizeof(struct node));
        printf("\nEnter data:");
        scanf("%d",&newnode->data);
        newnode->next=a->next;
        newnode->prev=a;
        a->next=newnode;
    }

Function For Insert at Last Position:

void insert_last()
{
    struct node *d=head;
    newnode=(struct node*)malloc(sizeof(struct node));
    printf("\nEnter data:");
    scanf("%d",&newnode->data);
    while(d->next!=NULL)
    {d=d->next;}
    d->next=newnode;
    newnode->prev=d;
    newnode->next=NULL;
}

Full Program for Insertion:

#include<stdio.h>
#include<stdlib.h>
struct node{
    struct node *prev;
    int data;
    struct node *next;
};
struct node *head,*newnode,*temp,*disp;
void create()
{
    int i,num;
    printf("\nHow many Nodes you want to create:");
    scanf("%d",&num);
    for(i=1; i<=num; i++)
    {
    newnode=(struct node *)malloc(sizeof(struct node));
    printf("\nEnter data:");
    scanf("%d",&newnode->data);
    if(head==NULL)
    {
        head=temp=newnode;
    }else{
        temp->next=newnode;
        newnode->prev=temp;
        newnode->next=NULL;
        head->prev=NULL;
        temp=temp->next;
    }}}
    void insert_beg()
    {
        newnode=(struct node *)malloc(sizeof(struct node));
        printf("\nEnter data:");
        scanf("%d",&newnode->data);
        newnode->next=head;
        newnode->prev=NULL;
        head->prev=newnode;
        head=newnode;
    }
    void insert_spec()
    {
        struct node *a=head,*b=head;
        int i,j,pos;
        printf("\nEnter Position where you want to add NewNode:");
        scanf("%d",&pos);
        for(i=1; i<pos-1; i++)
        {a=a->next;
        }
        newnode=(struct node *)malloc(sizeof(struct node));
        printf("\nEnter data:");
        scanf("%d",&newnode->data);
        newnode->next=a->next;
        newnode->prev=a;
        a->next=newnode;
    }
void insert_last()
{
    struct node *d=head;
    newnode=(struct node*)malloc(sizeof(struct node));
    printf("\nEnter data:");
    scanf("%d",&newnode->data);
    while(d->next!=NULL)
    {d=d->next;}
    d->next=newnode;
    newnode->prev=d;
    newnode->next=NULL;
}

   
void display()
{
    disp=head;
    while(disp!=NULL)
    {
        printf("%d->",disp->data);
        disp=disp->next;
    }
}
void main()
{
    while(1)
    {
        int choice;
        printf("\n1.Create, \n2.Display, \n3.Insert at first position, \n4.Insert at specific Position, \n5.Insert at last Position, \n6.Exit");
        printf("\nEnter Choice:");
        scanf("%d",&choice);
        switch(choice)
        {
            case 1:
            create();
            break;
            case 2:
            display();
            break;
            case 3:
            insert_beg();
            break;
            case 4:
            insert_spec();
            break;
            case 5:
            insert_last();
            break;
            case 6:
            exit(0);
            break;
            default:
            printf("\nInvalid Input");
            break;
        }
    }
}

For Run Program With out any error use full Program.

Circular Singly Linked List Deletion

 Hello Friends,

Today we discuss about Circular Singly Linked List Deletion

Function for Delete Node From Beginning or Delete First Node:

 void delete_beg()
    {
       struct node *f=head;
       while(f->next!=head)
       {f=f->next;}
       head=head->next;
       f->next=head;
    }

Function for Delete Node From Specific Position or Delete in between:

 void delete_spec()
    {
        struct node *p=head;
        int i,pos;
        printf("\nEnter Position where you want to add node:");
        scanf("%d",&pos);
        for(i=1; i<pos-1; i++)
        {p=p->next;}
        newnode=(struct node *)malloc(sizeof(struct node));
        printf("\nEnter data:");
        scanf("%d",&newnode->data);
        newnode->next=p->next;
        p->next=newnode;
}

Function for delete last Node:

 void delete_spec()
    {
        struct node *p=head,*q=head;
        int i,pos,j;
        printf("\nEnter Position which you want to delete:");
        scanf("%d",&pos);
        for(i=1; i<pos-1; i++)
        {p=p->next;}
       for(j=1; j<pos; j++)
       {
        q=q->next;
       }
       p->next=q->next;
       free(q);
    }

Full Program For Deletion:

#include<stdio.h>
#include<stdlib.h>
struct node {
    int data;
    struct node *next;
};
struct node *newnode,*head,*temp;
void create()
{
    int i,num;
    printf("\nEnter How many nodes you want to create:");
    scanf("%d",&num);
    for(i=1; i<=num; i++){
    newnode=(struct node *)malloc(sizeof(struct node));
    printf("\nEnter data:");
    scanf("%d",&newnode->data);
    if(head==NULL)
    {
        head=temp=newnode;
        newnode->next=head;
    }else{
        newnode->next=head;
        temp->next=newnode;
        temp=temp->next;
    }}}
    void display()
    {
        struct node *disp=head;
        while(disp->next!=head)
        {
            printf("%d",disp->data);
            disp=disp->next;
        }
        printf("%d",disp->data);
    }
    void delete_beg()
    {
       struct node *f=head;
       while(f->next!=head)
       {f=f->next;}
       head=head->next;
       f->next=head;
    }
    void delete_spec()
    {
        struct node *p=head,*q=head;
        int i,pos,j;
        printf("\nEnter Position which you want to delete:");
        scanf("%d",&pos);
        for(i=1; i<pos-1; i++)
        {p=p->next;}
       for(j=1; j<pos; j++)
       {
        q=q->next;
       }
       p->next=q->next;
       free(q);
    }
    void delete_last()
    {
        struct node *last=head,*a;
        while(last->next!=head)
        {
            a=last;
            last=last->next;
        }
        a->next=head;
        free(last);
        last=NULL;
    }
   
    void main()
    {
        while(1)
        {
            int choice;
            printf("\n1.Create,\n2.display,\n3.Delete First Node, \n4.Delete specific position,\n5.Delete Last Node,\n6.Exit");
            printf("\nEnter Your Choice:");
            scanf("%d",&choice);
            switch(choice)
            {
                case 1:
                create();
                break;
                case 2:
                display();
                break;
                case 3:
                delete_beg();
                break;
                case 4:
                delete_spec();
                break;
                case 5:
                delete_last();
                break;
                case 6:
                exit(0);
                break;
                default:
                printf("\nEnter Correct Option:");
                break;
            }
        }
getch();
}

For Run Program with out any error use full program.

Saturday, January 28, 2023

Circular Singly Linked List Insertion Functions

 Hello friends, 

Today we discuss about Circular Singly Linked List.

Create a circular singly linked list:

Function Create:

void create()
{
int i,num;
printf("\nHow many nodes you want to create:");
scanf("%d",&num);
for(i=1; i<=num; i++)
{
newnode=(struct node*)malloc(sizeof(struct node));
printf("\nEnter data:");
scanf("%d",&newnode->data);
if(head==NULL)
{
head=temp=newnode;
}else{
temp->next=newnode;
newnode->next=head;
temp=temp->next;
}}}

Function Display:

void display()
{
struct node *disp=head;
while(disp->next!=head)
{
printf("%d->",disp->data);
disp=disp->next;
}
printf("%d->",disp->data);
}

Function Insert Node at Beginning:

void insert_beg()
{
struct node *p=head;
newnode=(struct node*)malloc(sizeof(struct node));
printf("\nEnter data:");
scanf("%d",&newnode->data);
while(p->next!=head)
{
p=p->next;
}
newnode->next=p->next;
p->next=newnode;
head=newnode;
}

Function Insert Node at specific position or insert inbetween:

void specific()
{
int i,pos;
struct node *posi=head;
newnode=(struct node*)malloc(sizeof(struct node));
printf("\nEnter data:");
scanf("%d",&newnode->data);
printf("\nEnter position:");
scanf("%d",&pos);
if(pos==1)
{
printf("\nUse Insert at Beginning Function");
}
for(i=1; i<pos-1; i++)
{ posi=posi->next;}
newnode->next=posi->next;
posi->next=newnode;
}

Function Insert Node at last Position:

void last()
{
struct node *last=head;
newnode=(struct node *)malloc(sizeof(struct node));
printf("\nEnter data:");
scanf("%d",&newnode->data);
while(last->next!=head)
{last=last->next;}
last->next=newnode;
newnode->next=head;
}

Full Program For Circular Singly Linked List Insertion:

#include<stdio.h>
#include<stdlib.h>
struct node {
int data;
struct node *next;
};
struct node *newnode,*head,*temp;
void create()
{
int i,num;
printf("\nHow many nodes you want to create:");
scanf("%d",&num);
for(i=1; i<=num; i++)
{
newnode=(struct node*)malloc(sizeof(struct node));
printf("\nEnter data:");
scanf("%d",&newnode->data);
if(head==NULL)
{
head=temp=newnode;
}else{
temp->next=newnode;
newnode->next=head;
temp=temp->next;
}}}
void insert_beg()
{
struct node *p=head;
newnode=(struct node*)malloc(sizeof(struct node));
printf("\nEnter data:");
scanf("%d",&newnode->data);
while(p->next!=head)
{
p=p->next;
}
newnode->next=p->next;
p->next=newnode;
head=newnode;
}

void specific()
{
int i,pos;
struct node *posi=head;
newnode=(struct node*)malloc(sizeof(struct node));
printf("\nEnter data:");
scanf("%d",&newnode->data);
printf("\nEnter position:");
scanf("%d",&pos);
if(pos==1)
{
printf("\nUse Insert at Beginning Function");
}
for(i=1; i<pos-1; i++)
{ posi=posi->next;}
newnode->next=posi->next;
posi->next=newnode;
}
void last()
{
struct node *last=head;
newnode=(struct node *)malloc(sizeof(struct node));
printf("\nEnter data:");
scanf("%d",&newnode->data);
while(last->next!=head)
{last=last->next;}
last->next=newnode;
newnode->next=head;
}


void display()
{
struct node *disp=head;
while(disp->next!=head)
{
printf("%d->",disp->data);
disp=disp->next;
}
printf("%d->",disp->data);
}
void main()
{
create();
insert_beg();
specific();
last();
display();
getch();
}

For Execute Program Properly use Full Program.

Sunday, January 15, 2023

Singly Linked List Delete Last Node

Singly Linked List Delete At Last or Remove Last Node Function

Function Delete Last Node in Singly Linked List:
void delete_last()
{
    struct node *a,*b=head;
    while(b->next!=NULL)
    {
        a=b;
        b=b->next;
    }
    a->next=NULL;
    free(b);
    b=NULL;
}

Full Program:
#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node *next;
};
struct node *newnode,*head,*temp;

void create()
{int num,i;
printf("\nHow many nodes you want to create:");
scanf("%d",&num);
for(i=0; i<num; i++)
{
newnode=(struct node *)malloc(sizeof(struct node));
printf("\nEnter Data:");
scanf("%d",&newnode->data);
newnode->next=NULL;
if(head==NULL)
{head=temp=newnode;}
else
{temp->next=newnode;
temp=temp->next;
}}}

void delete_last()
{
    struct node *a,*b=head;
    while(b->next!=NULL)
    {
        a=b;
        b=b->next;
    }
    a->next=NULL;
    free(b);
    b=NULL;
}
void display()
{
    struct node *p;
p=head;
while(p->next!=NULL)
{
printf("%d->", p->data);
p=p->next;
}
printf("%d->",p->data);
}
void main()
{
    create();
    display();
    delete_last();
    printf("\nAfter Deleting Last Node:")
    display();
    getch();
}
 
Output:


l

Singly Linked List Delete Specific Node or We also say In between

hello Guys,

Singly Linked List Insert at specific position or in between function.

Function For Deleting Specific Node:

void delete_specific()
{
    struct node *a,*b=head;
    int i,poition;
    printf("\nEnter Position which you want to delete:");
    scanf("%d",&position);
    for(i=1; i<position; i++)
    {
        a=b;
        b=b->next;
    }
    a->next=b->next;
    free(b);
}

Full Program:

#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node *next;
};
struct node *newnode,*head,*temp;

void create()
{int num,i;
printf("\nHow many nodes you want to create:");
scanf("%d",&num);
for(i=0; i<num; i++)
{
newnode=(struct node *)malloc(sizeof(struct node));
printf("\nEnter Data:");
scanf("%d",&newnode->data);
newnode->next=NULL;
if(head==NULL)
{head=temp=newnode;}
else
{temp->next=newnode;
temp=temp->next;
}}}

void delete_specific()
{
    struct node *a,*b=head;
    int i,poition;
    printf("\nEnter Position which you want to delete:");
    scanf("%d",&position);
    for(i=1; i<position; i++)
    {
        a=b;
        b=b->next;
    }
    a->next=b->next;
    free(b);
}

void display()
{
    struct node *p;
p=head;
while(p->next!=NULL)
{
printf("%d->", p->data);
p=p->next;
}
printf("%d->",p->data);
}
void main()
{
    create();
    display();
    delete_specific();
    display();
    getch();
}

Output:



Singly Linked List Delete First Node From Linked List

 Welcome Friends,

Singly Linked List Delete First Node Function. It Just a Three Line Code. For Execute this, Use Full Program.

Function for Delete First Node:

void delete_first()
{
    struct node *a=head;
    head=a->next;
    free(a);
    a=NULL;    
}

Full Program:

#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node *next;
};
struct node *newnode,*head,*temp;

void create()
{int num,i;
printf("\nHow many nodes you want to create:");
scanf("%d",&num);
for(i=0; i<num; i++)
{
newnode=(struct node *)malloc(sizeof(struct node));
printf("\nEnter Data:");
scanf("%d",&newnode->data);
newnode->next=NULL;
if(head==NULL)
{head=temp=newnode;}
else
{temp->next=newnode;
temp=temp->next;
}}}

void delete_first()
{
    struct node *a=head;
    head=a->next;
    free(a);
    a=NULL;    
}

void display()
{
    struct node *p;
p=head;
while(p->next!=NULL)
{
printf("%d->", p->data);
p=p->next;
}
printf("%d->",p->data);
}

Output: