Community Sites
Create your own community website and start earning today !
It's Free !
 
Communities Members BookmarksPolls Fresher Jobs Funny Pictures MCA Projects New Member FAQ  



My Profile
Active Members
TodayLast 7 Days more...



Awards & Gifts
Online Exams

Fresher Jobs


Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian cities including Bangalore, Chennai, Hyderabad, Pune or Kochi

Resources


Find educational articles, blogs, discussion threads and other resources.

Colleges


Find details about any college in India or search for courses.

website counter




PROGRAM FOR LINK LIST IN C++


Posted Date: 16 Feb 2008    Resource Type: Articles/Knowledge Sharing    Category: Computer & Technology

Posted By: Gurpreet Singh       Member Level: Gold
Rating:     Points: 3



//PROGRAM FOR LINKED LIST..............//

#include
#include
#include

struct node
{
int info;
struct node *link;
};

typedef struct node NODE;

NODE *start,*p,*ptr;

NODE * create_node() //function for creating a node
{
p=(NODE *)malloc(sizeof (NODE));
printf("\nENTER THE INFORMATION : ");
scanf("%d",&p->info);
p->link=NULL;
return p;
}

void traverse() //function for traversing the list
{
ptr=start;
while(ptr!=NULL)
{
printf("\n%d",ptr->info);
ptr=ptr->link;
}
}

void insert_at_beg() //function for insertion at beggining
{
ptr=create_node();
if(start==NULL)
ptr->link=NULL;
else
ptr->link=start;
start=ptr;
}

void insert_at_mid() //function for insertion in middle
{
int pos,i;
NODE *temp;
ptr=create_node();
printf("\nENTER THE POSITIONB AT WHICH NODE IS TO BE INSERTED : ");
scanf("%d",&pos);
temp=start;
for(i=1;i temp=temp->link;
ptr->link=temp->link;
temp->link=ptr;
}

void insert_at_end() //function for insertion at end
{
NODE *temp;
ptr=create_node();
temp=start;
while(temp->link!=NULL)
temp=temp->link;
temp->link=ptr;
}

void deletion_at_beg() //function for deletion at beggining
{
int item;
ptr=start;
start=ptr->link;
item=ptr->info;
printf("\nITEM DELETED IS : %d",item);
free (ptr);
}

void deletion_at_mid() //function for deletion in middle
{
int item,pos,i;
NODE *temp,*temp1;
printf("\nENTER THE POSITION FROM WHICH NODE IS TO BE DELETED : ");
scanf("%d",&pos);
ptr=start;
for(i=1;i {
temp=ptr;
ptr=ptr->link;
}
item=ptr->info;
printf("\nITEM DELETED IS : %d",item);
temp->link=ptr->link;
free (ptr);
}


void deletion_at_end() //function for deletion at end
{
int item;
NODE *temp;
ptr=start;
while(ptr->link!=NULL)
{
temp=ptr;
ptr=ptr->link;
}
temp->link=NULL;
item=ptr->info;
printf("\nITEM DELETED IS : %d",item);
free (ptr);
}

void main()
{
int ch,ans,choice;
clrscr();
printf("\nCREATING THE LINK LIST.......\n");
start=create_node();
ptr=start;
for( ; ;)
{
printf("\nDO YOU WANT TO ENTER MORE NODE?(Y/N) : ");
scanf("%s",&ans);
if(ans=='y' || ans=='Y')
{
ptr->link=create_node();
ptr=ptr->link;
}
else
break;
}
printf("\n\nMENU:-\n");
printf("\n1.TRAVERSING THE LIST\n");
printf("\n2.INSERTION AT BEGGINING\n");
printf("\n3.INSERTION AT MIDDLE\n");
printf("\n4.INSERTION AT END\n");
printf("\n5.DELETION AT FRONT\n");
printf("\n6.DELETION AT MIDDLE\n");
printf("\n7.DELETION AT END\n");
do
{
printf("\n\nENTER YOUR CHOICE(1-7) : ");
scanf("%d",&ch);
switch(ch)
{
case 1: traverse();
break;
case 2: insert_at_beg();
break;
case 3: insert_at_mid();
break;
case 4: insert_at_end();
break;
case 5: deletion_at_beg();
break;
case 6: deletion_at_mid();
break;
case 7: deletion_at_end();
break;
default: printf("\n\nWRONG CHOICE ENTERED!!!!");
}
printf("\n\nDO YOU WANT TO CONTINUE?(Y/N) : ");
scanf("%s",&choice);
}while(choice=='y' || choice=='Y');
getch();
}




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Convert code between C# & VB.NET
Previous Resource: Circular doubly linked list.
Return to Discussion Resource Index
Post New Resource
Category: Computer & Technology


Post resources and earn money!
 
Related Resources

Watch TV Channels



Contact Us    Editors    Privacy Policy    Terms Of Use   

SpiderWorks Technologies Pvt Ltd. 2006 - 2007 All Rights Reserved.