Apr 2, 2011

Write a program to perform all operations on singly Circular linked list

#include
#include
struct abc
{
int info;
struct abc *link;
};
struct abc *f = NULL, *prev = NULL;
void main()
{
int ch;
do
{
clrscr();
printf("\n Linked list");
printf("\n 1. Insert");
printf("\n 2. Display");
printf("\n 3. Delete ");
printf("\n 4. Search");
printf("\n 5. Exit");
printf("\n Enter your choice :");
scanf("%d",&ch);
switch(ch)
{
case 1:
insert();
getch();
continue;
case 2:
display();
getch();
continue;
case 3:
delete();
getch();
continue;
case 4:
search();
getch();
continue;
}
}while(ch!= 5);
}
insert()
{
struct abc *new;
new = (struct abc *) malloc(sizeof(struct abc));
printf("\n Enter value :");
scanf("%d",&new->info);
if(f==NULL && prev == NULL)
{
f=new;
prev= new;
new->link = f;
return;
}
prev->link = new;
new->link = f;
prev = new;
return;
}
display()
{
struct abc *x;
if(f==NULL && prev == NULL)
{
printf("\n Linked List is Empty");
return;
}
x=f;
do
{
printf("\n Value is : %d", x->info);
x = x->link;
}while(x!=f);
return;
}
delete()
{
struct abc *p,*q;
int x;
if(f==NULL && prev == NULL)
{
printf("\n Linked List is Empty");
return;
}
printf("\n Enter element to delete : ");
scanf("%d",&x);
if(f->info == x && f == prev)
{
f = NULL;
prev = NULL;
return;
}
if(f->info == x)
{
f = f->link;
prev->link = f;
return;
}
p=f;
do
{
q=p;
p=p->link;
}while(p!=f && p->info != x);

if(p->info == x && p == prev)
{
q->link = p->link;
prev = q;
return;
}
if(p->info == x)
{
q->link = p->link;
return;
}
printf("\n Element not found in the list ");
return;
}
search()
{

struct abc *p,*q;
int x,flag=0;
if(f==NULL && prev == NULL)
{
printf("\n Linked List is Empty");
return;
}
printf("\n Enter element to search : ");
scanf("%d",&x);
p=f;
do
{
if(p->info == x)
{
flag = 1;
break;
}
p=p->link;
}while(p!= f);
if(flag)
printf("\n Element found in the list ");
else
printf("\n Element not found in the list ");
return;
}

Write a program to perform all operations on singly unordered linked list

#include
#include
struct abc
{
int info;
struct abc *link;
};
struct abc *f = NULL, *prev = NULL;
void main()
{
int ch;
do
{
clrscr();
printf("\n Linked list");
printf("\n 1. Insert");
printf("\n 2. Display");
printf("\n 3. Delete ");
printf("\n 4. Search");
printf("\n 5. Sort");
printf("\n 6. Exit");
printf("\n Enter your choice :");
scanf("%d",&ch);
switch(ch)
{
case 1:
insert();
getch();
continue;
case 2:
display();
getch();
continue;
case 3:
delete();
getch();
continue;
case 4:
search();
getch();
continue;
case 5:
sort();
getch();
continue;
}
}while(ch!= 6);
}
insert()
{
struct abc *new;
new = (struct abc *) malloc(sizeof(struct abc));
printf("\n Enter value :");
scanf("%d",&new->info);
if(f==NULL && prev == NULL)
{
f=new;
prev= new;
new->link = NULL;
return;
}
prev->link = new;
new->link = NULL;
prev = new;
return;
}
display()
{
struct abc *x;
if(f==NULL && prev == NULL)
{
printf("\n Linked List is Empty");
return;
}
x=f;
while(x!=NULL)
{
printf("\n Value is : %d", x->info);
x = x->link;
}
return;
}
delete()
{
struct abc *p,*q;
int x;
if(f==NULL && prev == NULL)
{
printf("\n Linked List is Empty");
return;
}
printf("\n Enter element to delete : ");
scanf("%d",&x);
if(f->info == x && f == prev)
{
f = NULL;
prev = NULL;
return;
}
if(f->info == x)
{
f = f->link;
return;
}
p=f;
while(p!=NULL && p->info != x)
{
q=p;
p=p->link;
}
if(p->info == x && p == prev)
{
q->link = p->link;
prev = q;
return;
}
if(p->info == x)
{
q->link = p->link;
return;
}
printf("\n Element not found in the list ");
return;
}
search()
{

struct abc *p,*q;
int x,flag=0;
if(f==NULL && prev == NULL)
{
printf("\n Linked List is Empty");
return;
}
printf("\n Enter element to search : ");
scanf("%d",&x);
p=f;
while(p!=NULL)
{
if(p->info == x)
{
flag = 1;
break;
}
p=p->link;
}
if(flag)
printf("\n Element found in the list ");
else
printf("\n Element not found in the list ");
return;
}
sort()
{
struct abc *p,*q;
int x;
if(f==NULL && prev == NULL)
{
printf("\n Linked List is Empty");
return;
}
for(p=f;p!=NULL;p=p->link)
{
for(q=p;q!=NULL;q=q->link)
{
if(p->info > q->info)
{
x = p->info;
p->info = q->info;
q->info = x;
}
}
}
display();
return;
}

Write a program to perform all operations on singly ordered linked list

#include
#include
struct abc
{
int info;
struct abc *link;
};
struct abc *f = NULL, *prev = NULL;
void main()
{
int ch;
do
{
clrscr();
printf("\n Linked list");
printf("\n 1. Insert");
printf("\n 2. Display");
printf("\n 3. Delete ");
printf("\n 4. Search");
printf("\n 5. Exit");
printf("\n Enter your choice :");
scanf("%d",&ch);
switch(ch)
{
case 1:
insert();
getch();
continue;
case 2:
display();
getch();
continue;
case 3:
delete();
getch();
continue;
case 4:
search();
getch();
continue;
}
}while(ch!= 5);
}
insert()
{
struct abc *new,*p,*q;
new = (struct abc *) malloc(sizeof(struct abc));
printf("\n Enter value :");
scanf("%d",&new->info);
if(f==NULL && prev == NULL)
{
f=new;
prev= new;
new->link = NULL;
return;
}
if(new->info <=f->info)
{
new->link = f;
f=new;
return;
}
if(new->info >= prev->info)
{
prev->link = new;
new->link = NULL;
prev = new;
return;
}
p =f;
while(p->info <= new->info)
{
q=p;
p=p->link;
}
q->link = new;
new->link = p;
return;
}
display()
{
struct abc *x;
if(f==NULL && prev == NULL)
{
printf("\n Linked List is Empty");
return;
}
x=f;
while(x!=NULL)
{
printf("\n Value is : %d", x->info);
x = x->link;
}
return;
}
delete()
{
struct abc *p,*q;
int x;
if(f==NULL && prev == NULL)
{
printf("\n Linked List is Empty");
return;
}
printf("\n Enter element to delete : ");
scanf("%d",&x);
if(f->info == x && f == prev)
{
f = NULL;
prev = NULL;
return;
}
if(f->info == x)
{
f = f->link;
return;
}
p=f;
while(p!=NULL && p->info != x)
{
q=p;
p=p->link;
}
if(p->info == x && p == prev)
{
q->link = p->link;
prev = q;
return;
}
if(p->info == x)
{
q->link = p->link;
return;
}
printf("\n Element not found in the list ");
return;
}
search()
{

struct abc *p,*q;
int x,flag=0;
if(f==NULL && prev == NULL)
{
printf("\n Linked List is Empty");
return;
}
printf("\n Enter element to search : ");
scanf("%d",&x);
p=f;
while(p!=NULL)
{
if(p->info == x)
{
flag = 1;
break;
}
p=p->link;
}
if(flag)
printf("\n Element found in the list ");
else
printf("\n Element not found in the list ");
return;
}

mkdir

mkdir command is used to create directories. The command is followed by the names of the directories to be created.

$ mkdir virani

This command creates the directories virani

$ mkdir stud1 stud2 stud3

This command will create three directories stud1,stud2,and stud3.

$ mkdir virani virani/sci virani/arts

This creates three directories virani,two sub directories sci and arts under virani.The order of specifying arguments is important; you obviously can’t create a sub directory before creation of its parent directory.

Sometimes the system refuses to create a directory:

$mkdir maths

mkdir : can’t make directory maths

This can happen due to these reasons:
• The directory maths may already exist.
• There may be an ordinary file by that name in the current directory.
• The user doesn’t have the permission to create a directory.

who am i

The who command ,when used with the arguments “am” and “I”, displays a single line output only,i.e the login detail pertaining to the user who invoked this command.


$ who am i
vsc tty01 Dec 25 09:35

who command

who command gives the list of the users currently working on various terminals.
$who
vsc tty01 Dec 25 09:35
atmiya tty02 Dec 25 08:50
student tty03 Dec 25 09:45

$who –Hu

USER LINE LOGIN-TIME IDLE PID COMMENTS

vsc tty01 Dec 25 09:35 . 24
student tty02 Dec 25 09:40 0:30 25

-H is for header and –u option provides more detailed list
The idle column shows that student seems to be idling for last6 30 minutes. PID shows the process identification number.

passwd command



passwd command is used to change passwords
$ passwd
old password:
new password:
Re-enter new password:

            Passwd when invoked by ordinary user ,it asks for old password. After which it demands to enter new password twice. if you are logged on as root you can directly change the password.

In Linux
[root@localhost]passwd vsc
changing password for vsc
new password: