You feel excited to learn computer languages

Then you are at the right place. Computer languages are most fun thing you have ever seen. Use this excellent languages and have a nice future...

How computer can help you?

I will ask how it can not? From the latest trend of social networking sites like Facebook, Twitter to the extended use of computer in our house hold devices. You can be benefited from computer in the every aspect of life.

What web technology?

It is the blessings of web technology, that brings you here and you are reading my post now. Strange huh!! Not at all. Use my web technology tutorials and understand, how they can help you for better marketing and advertising systems.

How Mobile technology can help us?

You have answer right? I know. But in my tutorials I will cover some unique features that may add some information in your hard disk too. Sounds good? Check them...

Computer and future

Yes that is the most important question to me. What is next? What is going to be the next big thing for us? Well I will answer them in my blog. Check the corresponding section..

Showing posts with label "link list". Show all posts
Showing posts with label "link list". Show all posts

Saturday, November 5, 2011

Link List Creation, Insertion, Deletion, Searching


This is the part 1 one of Link list operation


#include<conio.h>
#include<stdio.h>
#include<alloc.h>
//Creation of node
struct node
{
int value;
struct node *next;
};
//inserting new nodes
void insert(struct node **start,int v)
{
struct node *ptr;

ptr=(struct node *)malloc(sizeof(struct node *));
ptr->next=NULL;
ptr->value=v;

if(*start==NULL)
printf("\nList is empty. Please create the list first....");
else
{
ptr->next=*start;
*start=ptr;
}
}
//creation of the first node in the list
void create_list(struct node **start,int v)
{
struct node *ptr;

ptr=(struct node *)malloc(sizeof(struct node *));
ptr->next=NULL;
ptr->value=v;

if(*start==NULL)
*start=ptr;
else
printf("\nList has been already created.....");
}
//delete the whole list
void del_whole(struct node **start)
{
if(*start!=NULL)
*start=NULL;
else
printf("\nUnder flow.....");
}
//disply the list
void display(struct node *start)
{
struct node *ptr;
ptr=start;
printf("\nStart Pointer is at %u\n",start);
while(ptr!=NULL)
{
printf("\nAddress %u Value %d\tNext %u",ptr,ptr->value,ptr->next);
ptr=ptr->next;
}
}
//find value from the list
void find(struct node *start,int val)
{
struct node *ptr;
int flag=0;
ptr=start;
while(ptr!=NULL)
{
if(ptr->value==val)
{
flag=1;
break;
}
else
ptr=ptr->next;
}
if(flag==1)
printf("Value is present at position %u",ptr);
else
printf("Sorry your value is not present");
}
//find minimum number from the link list
void min(struct node *start)
{
struct node *ptr;
int m;
ptr=start;
m=ptr->value;
while(ptr!=NULL)
{
if(ptr->value<m)
m=ptr->value;
ptr=ptr->next;
}
printf("Minimum %u",m);
}

void main()
{
char ch;
int v;
struct node *start=NULL;
clrscr();
//run the loop until user wants to to exit by option 7
do
{
//option list
printf("\n1.Create List\n2.Insert\n3.Delete Whole list\n4.Search value\n5.Display\n6.Find Minimum\n7.Exit");
printf("\nEnter your choice:>>");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("Enter value:");
scanf("%d",&v);
create_list(&start,v);
break;
case 2:
printf("Enter value:");
scanf("%d",&v);
insert(&start,v);
break;
case 3:
del_whole(&start);
break;
case 4:
printf("Enter value:");
scanf("%d",&v);
find(start,v);
getch();
break;
case 5:
display(start);
getch();
break;
case 6:
min(start);
getch();
break;
default:
printf("Invalid option has been selected...");
}
}while(ch!=7);//end of the loop
}//end of the prog