NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

88888888888888888888888888888888888888888888888888888888888888888888888888888

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

///Doubly Linked List (DLL) of Employee Data with the fields: SSN, Name, Dept, Designation,Sal, PhNo


struct node
{
char ssn[10],name[10],dept[15],desig[15],phno[10];
float sal;
struct node *llink;
struct node *rlink;
};
typedef struct node *NODE;
NODE temp, FIRST=NULL,END=NULL;

/**********************************/
NODE getnode()
{
NODE x;
x=(NODE)malloc(sizeof(struct node));
return x;
}

/**********************************/
void read()
{
temp=getnode();
temp->llink=NULL;
temp->rlink=NULL;
printf("Enter SSN");
flushall();
gets(temp->ssn);

printf("Enter NAMe");
flushall();
gets(temp->name);

printf("Enter dept:");
flushall();
gets(temp->dept);
printf("Enter designation:");
flushall();
gets(temp->desig);

printf("Enter phno");
flushall();
gets(temp->phno);

printf("Enter salary");
scanf("%f",&temp->sal);
}

void Create_DLL()
{
int n,i=0;

printf("enter the number of Employees n");
scanf("%d",&n);
while(i!=n)
{
i++;
printf("Enter the details of the %d employeen", i);
read();

if(FIRST==NULL)

{
FIRST=temp ;
END=temp;
}

else{
END->rlink=temp;
temp->llink=END;
END=temp;
}

} //end of while
printf("Craetion of DLL for %d is done",i);
}


/**Display the status and count the number****/
void display_count()
{
NODE temp1=FIRST;
int count=1;

printf("the employee details n");

if(temp1==NULL)
{
printf("the employee detail is NULL and count is %dn",count-1);
}

else
{
while(temp1!=END)
{
count++;
printf("%st%s",temp1->ssn,temp1->name);
temp1=temp1->rlink;
}

printf("%st%s",temp1->ssn,temp1->name);
printf("the student count is %dn",count);
}


return;
}
/********************Insertionfront();********/
void Insertionfront()
{
printf("enetr the details of the employeen");
read();
if(FIRST==NULL)
FIRST=temp ;

else
{
temp->rlink=FIRST;
FIRST->llink=temp;
FIRST=temp;
}
}

void Insertionend()
{
temp=getnode();
temp->llink=NULL;
temp->rlink=NULL;
printf("enter the deatils of the new employeen");
read();
if(FIRST==NULL)
{
FIRST=temp;
END=temp;
}

else
{
END->rlink=temp;
temp->llink=END;
END=temp;
}
return ;
}
/******/

void Deletionfront()
{
NODE temp2 ;
if(FIRST==NULL)
{
printf("List is emptyn");
}
elseif(FIRST==END)
{
temp2=FIRST;
printf("deleted element is %sn", temp2->ssn);
FIRST=NULL;
END=NULL;

}
else {
temp2=FIRST;
printf("deleted element is %sn", temp2->ssn);
FIRST =FIRST->rlink;
temp2->llink=NULL;
free(temp2);
}
return;
}
void Deletionend()
{
NODE temp2 = END;
if(temp2==NULL)
{
printf("List is emptyn");
}
elseif(FIRST==END)
{

printf("deleted element is %sn", temp2->ssn);
FIRST=NULL;
END=NULL;

}
else
{
printf("deleted element is %sn", temp2->ssn);
END=END->llink;
END->rlink=NULL;
free(temp2);

}


return ;
}

void main()
{

//NODE temp,first = NULL;
int choice;
clrscr();
while(1)
{
printf("nnnt1.create DLL...t2.Display SLL..t3.Insertion at front...t4.Insertion at end...t...5.deletion at front...t6.deletion at end....t7.Demonstration of stck and Queue...t8.Exit...");
printf("nnntEnter Your Choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1: Create_DLL();break;
case 2:display_count();break;
case 3: Insertionfront(); break;
case 4: Insertionend(); break;
case 5:Deletionfront();break;
case 6:Deletionend();break;
//case 7:Demonstartion();break;
case 8:exit(0);
default: printf("nnntEnter proper Choice....");
}
}



}


99999999999999999999999999999999999999999999999999999999999999999999999999999

#include<stdio.h>
#include<conio.h>
#include<alloc.h>
#include<process.h>
#include<math.h>
struct node
{
float cf;
int px,py,pz;
int flag;
struct node *link;
};
typedef struct node *NODE;

NODE getnode()
{
NODE x;
x=(NODE) malloc (sizeof(struct node));
if(x==NULL)
{
printf("out of memoryn");
exit(0);
}
return x;
}

NODE insert_rear(float cf,float x , float y, float z,NODE head)
{
NODE temp,cur;
temp=getnode();
temp->cf=cf;
temp->px=x;
temp->py=y;
temp->pz=z;
temp->flag=0;
cur=head->link;
while(cur->link!=head)
{
cur=cur->link;
}
cur->link=temp;
temp->link=head;
return head;
}


void display(NODE head)
{
NODE temp;
if(head->link==head)
{
printf("polynominal doesn't exsitsn");
return;
}
temp=head->link;
while(temp!=head)
{
printf("+ % 5.2fx^%dy^%dz^%d",temp->cf,temp->px,temp->py,temp->pz);
temp=temp->link;
}
printf("n");
}
NODE add_poly(NODE h1,NODE h2, NODE h3)
{
NODE p1,p2;
int x1,x2,y1,y2,z1,z2,cf1,cf2,cf;
p1=h1->link;
while(p1!=h1)
{
x1=p1->px;
y1=p1->py;
z1=p1->pz;
cf1=p1->cf;
p2=h2->link;
while(p2!=h2)
{
x2=p2->px;
y2=p2->py;
z2=p2->pz;
cf2=p2->cf;
if(x1==x2 && y1==y2 && z1==z2) break;
p2=p2->link;
}
if(p2!=h2)
{
cf=cf1+cf2;
p2->flag=1;
if(cf!=0)
h3=insert_rear(cf,x1,y1,z1,h3);
}
else
h3=insert_rear(cf1,x1,y1,z1,h3);
p1=p1->link;
}

p2=h2->link;
while(p2!=h2)
{
if(p2->flag==0)
{
h3=insert_rear(p2->cf,p2->px,p2->py,p2->pz,h3);
}
p2=p2->link;
}
return h3;
}

NODE read_poly(NODE head)
{
int i;
int px,py,pz;
float cf;
printf("enter the coeffecient as -999 to end the polynominaln");
for(i=1;;i++)
{
printf("enter the %d termn",i);
printf("coeff=");
scanf("%f",&cf);
if(cf==-999) break;
printf("pow x=");
scanf("%d",&px);
printf("pow y=");
scanf("%d",&py);
printf("pow z=");
scanf("%d",&pz);

head=insert_rear(cf,px,py,pz,head);
}
return head;
}


void polysum()
{
NODE h1,h2,h3;
h1=getnode();
h2=getnode();
h3=getnode();
h1->link=h1;
h2->link=h2;
h3->link=h3;
printf("enter the first polynominaln");
h1=read_poly(h1);
printf("enter the second polynominaln");
h2=read_poly(h2);
h3=add_poly(h1,h2,h3);
printf(" the first polynominal isn");
display(h1);
printf("second polynominal isn");
display(h2);
printf("the sum of two polynominal isn");
display(h3);
}
void represent_evaluate()
{
NODE e1,temp;
int x,y,z;
float sum=0.0;
e1=getnode();
e1->link=e1;
printf("enter the polynominaln");
e1=read_poly(e1);
printf("polynominal i s n");
display(e1);
printf("enter the values of coefficientn");
scanf("%d%d%d",&x,&y,&z);
if(e1==NULL)
{
printf("list is empty");

}
else
{
temp=e1->link;
while(temp!=e1)
{

sum+=temp->cf*pow(x,temp->px)*pow(y,temp->py)*pow(z,temp->pz);
temp=temp->link;
}
// sum+=temp->cf*pow(x,temp->px)*pow(y,temp->py)*pow(z,temp->pz);
printf("the total sum is %fn",sum);
}
return;
}
void main()
{
int choice;
clrscr();
while(1)
{
printf("nnnt1.represent and evaluate...t2.ADD TWO poly..t3.Exit...");
printf("nnntEnter Your Choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1: represent_evaluate();break;
case 2:polysum();break;
case 3:exit(0);
default: printf("nnntEnter proper Choice....");
}
}

}


10000000000000000000000010101000000000001000000000000000000000000000000000

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define MAX 10

struct node
{
int info;
struct node *llink;
struct node *rlink;
};
typedef struct node* NODE;


NODE getnode()
{
NODE x;
x=(NODE) malloc (sizeof(struct node));
if(x==NULL)
{
printf("out of memoryn");
exit(0);
}
return x;
}
/*******************************************/
NODE insert(int item,NODE root)
{
NODE temp,cur,prev;
int i;
temp=getnode();
temp->info=item;
temp->llink=temp->rlink=NULL;
if(root==NULL)
{
root=temp;
return root;
}
else
{
prev=NULL;
cur=root;
while(cur!=NULL)
{
prev=cur;
cur=(temp->info<cur->info)?cur->llink:cur->rlink;
}

if(temp->info<prev->info)
prev->llink=temp;
else
prev->rlink=temp;
return root;
}
}



/***********************************************/
void pre(NODE PRE)
{
if(PRE!=NULL)
{
printf("%dt",PRE->info);
pre(PRE->llink);
pre(PRE->rlink);
}
}
void in(NODE IN)
{
if(IN!=NULL)
{
in(IN->llink);
printf("%dt",IN->info);
in(IN->rlink);
}
}
void post(NODE POST)
{
if(POST!=NULL)
{
post(POST->llink);
post(POST->rlink);
printf("%dt",POST->info);
}
}

void Traversal(NODE root)
{
NODE IN,PRE,POST;
IN=root;
PRE=root;
POST=root;
if(root == NULL)
{
printf("tree is emptyn");
return;
}
printf("preorder traversal....n");
pre(PRE);
printf("nInorder traversal....n");
in(IN);
printf("n Post order traversal....n");
post(POST);

}

search(NODE root)
{
int item,i=0;
NODE cur;
printf("enter the elemenet to be serachedn");
scanf("%d", &item);
if(root == NULL)
{
printf("tree is emptyn");
return;
}
cur=root;

while(cur!=NULL)
{
if(item ==cur->info)
{
i++;
printf("found key %d in treen",cur->info);

}

if(item <cur->info)

cur=cur->llink;

else
cur=cur->rlink;
}
if(i==0)
printf("key not foundn");
return ;
}

/*******************deletion*********************/
NODE deletion(NODE root,int key)
{
NODE cur,parent,suc,q;
if(root == NULL)
{
printf("tree is emptyn");
return root;
}
parent=NULL;cur=root;
while(cur!=NULL)
{
if(key ==cur->info)break;
parent=cur;
cur =(key<cur->info)?cur->llink:cur->rlink;

}
if(cur==NULL)
{
printf("Item not foundn");
return root;
}
if(cur->llink==NULL)
q=cur->rlink;
else if(cur->rlink==NULL)
q=cur->llink;
else
{
suc = cur->rlink;
while(suc->llink!=NULL)
suc=suc->llink;
suc->llink=cur->llink;
q=cur->rlink;
}
if(parent==NULL) return q;
if(cur==parent->llink)
parent->llink=q;
else
parent->rlink=q;
free(cur);
return root;
}









void main()
{
int choice,item;
NODE root=NULL;
clrscr();
while(1)
{
printf("nnnt1.create BST .t2.Traversal..t3.search....t4.delete .....t5.Exit...");
printf("nnntEnter Your Choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("enter the item to be insertedn");
scanf("%d",&item);
root=insert(item,root);
break;
case 2: Traversal(root);break;
case 3: search(root);break;
case 4: printf("enter the item to be deletedn");
scanf("%d",&item);
root = deletion(root,item);break;
case 5:exit(0);
default: printf("nnntEnter proper Choice....");
}
}

}

11111111111111111111111111111111111111111111111111111.1.1.1.1111111111111111111

#include<stdio.h>
#include<conio.h>
#include<math.h>
#define MAX 20
int G[MAX][MAX], n,visited1[10],visited[10];
/********Graph creation********/
void Creation_Graph()
{
printf("Enter the Number of Cities");
scanf("%d", &n);
printf("Enter the edges for the Cities");
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
scanf("%d",&G[i][j]);
}
}
printf("Adjacency matrix for the Cities is created succesfullyn");

}

/*********Reachability**********/

void Reachability(int source)
{
int f,r,q[10]; // for queue operations
int u,v; // represent two vertices
int i; // index variable
f=0;
r=-1;


q[++r]=source; // insert vertex into queue

visited1[source]=1; // add source to v (indicating source is visited)

while(f<=r) // as long as queue is not empty
{
u=q[f++]; // delete the next vertex to be explored from q

for(v=1;v<=n;v++)
{
// find the nodes v which are adjecent to u
if(visited1[v]==0 && G[u][v]==1)
{
visited1[v]=1; // add v to s indicates that v is visited now
r++;
q[r]=v; // insert new vertex into q for exploration
}
}
}

for(i=1;i<=n;i++)
{
if(visited1[i]==0)
{
printf("vertex %d is not reachablen",i);
}
else
printf("vertex %d is reachablen",i);
}


}




/********Connectivity***********/

// to insert the verices which are visited

void Connectivity(int source)
{ int visited[10];
int v,flag=1;
visited[source]=1;
for(v=1;v<=n;v++)
{
if(visited[v]==0 && G[source][v]==1)
Connectivity(v);
}
for(int i=1;i<=n;i++)
{
if(visited[i]==0)
flag = 0;
}

if(flag)
printf("n Graph is connected.....n");
else
printf("n Graph is not connected.....n");
}




void main()
{
int choice,source;
clrscr();
while(1)
{

printf("nnnt1.create a graph .t2.Test for reachability..t3.Test for connectivity......t4.Exit...");
printf("nnntEnter Your Choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1:Creation_Graph();break;
case 2:printf(" enter the source between 0 to %dn",n-1 );
scanf("%d",&source);
Reachability(source);break;

case 3: printf(" enter the source between 0 to %dn",n-1 );
scanf("%d",&source);
Connectivity(source);break;
case 4:exit(0);
default: printf("nnntEnter proper Choice....");
}
}

}

12222222222222222222222222222222222222222222222222222222222222222222222222222

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
//#include<file.h>
#include<string.h>

int emp_id,SSN;
char emp_name[10];
int emp_income;
char buffer[100];

int hash(int empid)
{
int t=empid;
t = empid % 99;
if (t==0) return 99;//assuming hash table has 10 locations from 0-9;
else return t;
}



void Write_to_file()
{
FILE *fp;
char temp[100];
int count,pos,n;
printf("Enter the details of an employeen : empid: must be of 4 digits ");
scanf("%d",&emp_id);
printf(" employee name: n");
flushall();
gets(emp_name);
printf(" employee income: n");
scanf("%d",&emp_income);
flushall();
sprintf(buffer,"%d|%s|%dn",emp_id,emp_name,emp_income);
printf("%sn",buffer);
pos=hash(emp_id);
pos--;
pos=pos*304;

fp = fopen("tw","w");
if(fp==-1)
{
printf("file can not be created");
}
fseek( fp, pos, SEEK_SET );
fscanf(fp,"%s",temp);

count = temp[0]-48;

if (count<0)
{
//fseek(fp,pos,SEEK_SET);
fputs("1",fp);
pos=pos+1;
}
else if (count==1)
{
fseek(fp,pos,SEEK_SET);
fputs("2",fp);
pos=pos+102;
}
else if (count==2)
{

fseek(fp,pos,SEEK_SET);
fputs("3",fp);
pos=pos+203;
}

//fseek(fp,pos,SEEK_SET);


n=fprintf(fp,"%d|%s|%dn",emp_id,emp_name,emp_income);
fputs("preethi",fp);
fclose(fp);
printf("nnn value is %d",n);
if (count==3)
printf("nnCannot Insert....Overflown");
}

void unpack(int flag)
{

char ssn[10];
int i=0;
flushall();

if (flag==1) i++;
while (buffer[i]!='|')
strcat(ssn,buffer[i++]);

SSN=atoi(ssn);

return;

}




/*
void Read_from_file(int empid)
{
FILE *fp1;
int flag=0,pos=0,count,i=1;
char temp[100];
pos=hash(empid);
pos--;
pos=pos*304;
fp1 = fopen("one.txt","w");
fseek( fp1, pos, SEEK_SET );
getline(fp1,temp);
count = temp[0]-48;
fseek( fp1, pos+1, SEEK_SET );
while (i<=count)
{
flushall();
getline(fp1,buffer);
unpack(i++);
if (empid==SSN) flag=1;
}
if (!flag) printf("nnKey not found:");
else
{
printf("the deatils of the employee aren");
printf("%sn",buffer);
}
fclose(fp1);
}
*/

void main()
{
int choice,empid;
clrscr();
while(1)
{

printf("nnnt1.write_to_File .t2.read_fromfile..t3.Exit...");
printf("nnntEnter Your Choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1:Write_to_file();break;
/* case 2:printf("enter the emp id for retrivaln");
scanf("%d",empid);
Read_from_file(empid);break; */

case 3:exit(0);
default: printf("nnntEnter proper Choice....");
}
}

}
     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.