Forum     

Go Back   Digit Technology Discussion Forum > Portables, Peripherals and Electronics > QnA (read only)
Register FAQ Calendar Mark Forums Read

QnA (read only) Mods please help transfer the contents of this forum to proper sections. :)


 
 
LinkBack Thread Tools Search this Thread Display Modes
Old 26-08-2007, 10:35 PM   #1 (permalink)
Hey here is the aks
 
arunks's Avatar
 
Join Date: Jan 2006
Location: punjab
Posts: 805
Default Hey i m getting only one error...Plz help to rectify that


I m writing a program for various operations on linked list in C... Program is given below.. and i m getting one error and two warnings..
Plz see by executing it and help me to remove it and run the program successfully...

Code:
#include<stdio.h>
#include<conio.h>

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

void create_list(struct node **head)
{
*head = (struct node *) NULL;
}

struct node *search(struct node *head,int item)
{
while(head!=(struct node *) NULL)
{
if(head->info==item)
return head;
head=head->next;
}
return NULL;
}

void insert_at_beginning(struct node *head,int item)
{
struct node *ptr;
ptr=(struct node *) malloc (sizeof(struct node));
ptr->info=item;
if(head==(struct node *)NULL)
{
ptr->next=(struct node *)NULL;
}
else
ptr->next=head;
head=ptr;
}

void insert_at_end(struct node *head,int item)
{
struct node *ptr;
ptr=(struct node * )malloc(sizeof(struct node));
ptr->info=item;
ptr->next=(struct node *)NULL;
if(head==(struct node *)NULL)
{
head=ptr;
}
else
{
while(head->next!=(struct node *)NULL)
{
head=head->next;
}
head->next=ptr;
}
}


void insert_after_element(struct node *head,int item,int after)
{
struct node *ptr,*loc;
loc =(struct node *) search(head,after);
if(loc== ( struct node * ) NULL )
{
printf("no element specified is there");
return;
}
ptr=(struct node *)malloc(sizeof(struct node));
ptr->info=item;
ptr->next=loc->next;
loc->next=ptr;
}

void traverse_list(struct node *head)
{
while(head!= (struct node * ) NULL)
{
printf("%d\n",head->info);
head=head->next;
}
}



void delete_at_beginning(struct node *head)
{
struct node *ptr;
if(head==(struct node *)NULL)
return;
else
{
ptr=head;
head= head->next;
free(ptr);
}
}

void delete_at_end(struct node *head)
{
struct node *ptr,*loc;
if(head== (struct node *)NULL)
return;
else
if(head->next==(struct node *)NULL)
{
ptr=head;
head=(struct node *)NULL;
free(ptr);
}
else
{
loc=head;
ptr=head->next;
while(ptr->next!= (struct node *)NULL)
{
loc=ptr;
ptr=ptr->next;
}
loc->next=(struct node *) NULL;
free(ptr);
}
}


void delete_after_element(struct node *head,int after)
{
struct node *ptr, *loc;
loc=search(head,after);
if(loc==(struct node *)NULL)
return;
ptr=loc->next;
loc->next=ptr->next;
free(ptr);
}

void delete_list(struct node *head)
{
struct node *ptr;
while(head != (struct node *)NULL)
{
ptr=head;
head=head->next;
free(ptr);
}
}


main()
{
struct node *head;
int choice,item,after;
clrscr();

printf("Linked List Program\n\n\n Press any key to start!!!!!!");

while(1)
{
clrscr();
printf("Linked List Program\n\n\n");
printf("1. Create a new linked list\n\n");
printf("2. Insert an element at the beginning\n\n");
printf("3. Insert an element after an element\n\n");
printf("4. Insert an element at end\n\n");
printf("5. Traverse all the elements of linked list\n\n");
printf("6. Search an element in linked list\n\n");
printf("7. Delete an element at the beginning\n\n");
printf("8. Delete an element after an element\n\n");
printf("9. Delete an element at end\n\n");
printf("10.Exit\n\n");
printf("\n\nEnter the choice:(1-10)");
scanf("%d",&choice);
if(choice<1 || choice>9)
{
clrscr();
printf("enter correct choice\n");
}
else
if(choice==1)
{
create_list(&head);
printf("empty List created\n");
}
else
if(choice==2)
{
printf("Enter the no. to store\n");
scanf("%d",&item);
insert_at_beginning(head,item);
}
else
if(choice==3)
{
printf("Enter the no. to store\n");
scanf("%d",&item);
printf("Enter no. after which %d is to be stored\n",item);
scanf("%d",&after);
insert_after_element(head,item,after);
}
else
if(choice==4)
{
printf("Enter the no. to store\n");
scanf("%d",&item);
insert_at_end(head,item);
}
else
if(choice==5)
{
if(head==(struct node *)NULL)
printf("\n List is empty......");
else
traverse_list(head);
printf("\nPress any ley to continue.......");
getch();
}
else
if(choice==7)
{
delete_at_beginning(head);
}
else
if(choice==8)
{
printf("Enter the no. after which item is to be deleted\n");
scanf("%d",&after);
delete_after_element(head,after);
}
else
if(choice==9)
{
delete_at_end(head);
}
else
if(choice==10)
{
delete_list(head);
exit(1);
}
}
getch();
}
__________________
yours truly
arun
The aks!!

have a nice day

Last edited by arunks; 27-08-2007 at 09:00 AM.
arunks is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 27-08-2007, 07:45 AM   #2 (permalink)
Dreamweaver
 
Gigacore's Avatar
 
Join Date: Aug 2006
Location: Bangalore
Posts: 3,904
Default Re: Hey i m getting only one error...Plz help to rectify that

please tell the error it states
__________________
Today's noobs are tomorrow's geeks. Don't make fun of them.. encourage them. - Gigacore

Follow me on twitter.com/gigacore
Gigacore is offline  
Old 27-08-2007, 09:01 AM   #3 (permalink)
Hey here is the aks
 
arunks's Avatar
 
Join Date: Jan 2006
Location: punjab
Posts: 805
Default Re: Hey i m getting only one error...Plz help to rectify that

I have removed the error myself... now program is executing without any error... but there is logical error i mean to say the output is not as expected.. plz check!!!
__________________
yours truly
arun
The aks!!

have a nice day
arunks is offline  
Old 31-08-2007, 09:09 AM   #4 (permalink)
Captain Jack Sparrow
 
jacksparrow18's Avatar
 
Join Date: Jan 2007
Location: Rajkot,Gujarat
Posts: 17
Thumbs down Re: Hey i m getting only one error...Plz help to rectify that

Quote:
Originally Posted by arunks
I have removed the error myself... now program is executing without any error... but there is logical error i mean to say the output is not as expected.. plz check!!!
write statement of ur prog!!!!!!!!!!!!!!
__________________
Gaurav Chauhan

The only thing i like about the stones is that they come in my life,and when i cross them automatically they become milestones of my life!!!
jacksparrow18 is offline  
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to rectify this....................? saurabh kakkar Open Source 4 27-06-2007 11:47 PM
plz help me to rectify this prob. saurabh kakkar QnA (read only) 4 19-05-2007 07:45 PM
fedora core 6 error..plz rectify arunks Open Source 3 28-03-2007 09:26 PM
Wats the best way to rectify winrar error ? vinyas Software Q&A 5 03-10-2006 02:45 PM
monitor out of Hz. can't rectify ra_sriniketan QnA (read only) 1 29-07-2005 10:51 PM

 
Latest Threads
- by Tenida
- by Charan

Advertisement




All times are GMT +5.5. The time now is 10:32 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2