468,458 Members | 1,777 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,458 developers. It's quick & easy.

deletion in link list

can anyone tell me how to delete a certain node in a doubly circular
link list
Dec 3 '07 #1
9 1597
ratika wrote:
can anyone tell me how to delete a certain node in a doubly circular
link list
Carefully...
Dec 3 '07 #2
On Dec 3, 4:36 pm, ratika <cool_ratikagu...@rediff.comwrote:
can anyone tell me how to delete a certain node in a doubly circular
link list
Let ptr holds the address of the node to be deleted then

(ptr->back)->next = ptr->next;
(ptr->next)->back = ptr->back;
free(ptr);

don't forget to check the boundary conditions
Dec 3 '07 #3
Chris Dollin wrote:

<snip>
[1] Programmers [2] are notable for their literal [3] interpretation
[of
questions.

[2] OK, /some/ programmers [3].

[3] And maybe it's rhetorical, not literal [4].

[4] Or a cover for the control messages to the mind-control satellites
[[4].

[4] There is no footnote 4.
Maybe you should use structured control flow instead of gotos?

Dec 3 '07 #4
santosh wrote:
Chris Dollin wrote:

<snip>
>[1] Programmers [2] are notable for their literal [3] interpretation
[of
questions.

[2] OK, /some/ programmers [3].

[3] And maybe it's rhetorical, not literal [4].

[4] Or a cover for the control messages to the mind-control satellites
[[4].

[4] There is no footnote 4.

Maybe you should use structured control flow instead of gotos?
I do.

--
Chris "they're procedures" Dollin

Hewlett-Packard Limited registered office: Cain Road, Bracknell,
registered no: 690597 England Berks RG12 1HN

Dec 3 '07 #5
ratika wrote:
can anyone tell me how to delete a certain node in a doubly circular
link list
<off-topic reason="better asked in comp.programming">

Draw a picture of the list, showing the links as arrows.
Then draw another picture of the list as it would be if the
deleted node were simply not there at all. Study the two
pictures to see which arrows have changed, and then write
code to make those changes in the actual list.

</off-topic>

--
Eric Sosman
es*****@ieee-dot-org.invalid
Dec 3 '07 #6
On Dec 3, 7:36 pm, ratika <cool_ratikagu...@rediff.comwrote:
can anyone tell me how to delete a certain node in a doubly circular
link list
read your book and understand the knowledge points yourself
try it yourself first
remember that practice makes perfect
Dec 3 '07 #7
On Dec 3, 7:21 pm, "Thomas X. Iverson" <thomas.x.iver...@gmail.com>
wrote:
On Dec 3, 7:36 pm, ratika <cool_ratikagu...@rediff.comwrote:
can anyone tell me how to delete a certain node in a doubly circular
link list

read your book and understand the knowledge points yourself
try it yourself first
remember that practice makes perfect
i know the concept of the program .i had made the program too . but
the problem is that it is running only two times not more than that
Dec 4 '07 #8
On Dec 3, 4:36 pm, ratika <cool_ratikagu...@rediff.comwrote:
can anyone tell me how to delete a certain node in a doubly circular
link list
//circular doubly link list
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct node
{
struct node *pre;
int data;
struct node *next;
};
void addnode(struct node** , int);
void display(struct node*);
void delfirst(struct node*);
void main()
{
int item,ch;
struct node **t;
clrscr();
*t=NULL;
do
{
printf("\nMenu:\n1.add node\n2.display\n3.delete first node\n4.exit
\nenter the choice");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("enter the value to be inserted");
scanf("%d",&item);
addnode(t,item);
break;
case 2:
display(*t);
break;
case 4:
break;
case 3:
delfirst(*t);
break;
default:
printf("wrong choice try again");
}
}while(ch!=3);
getch();
}
//functions starts
void addnode(struct node **t,int val)
{
struct node *temp,*temp1;
temp=(struct node*)malloc(sizeof(struct node));
temp->pre=NULL;
temp->data=val;
temp->next=NULL;
if(*t==NULL)
{
*t=temp;
temp->pre=*t;
temp->next=*t;
}
else
{
*t=temp1;
while(temp1->next!=*t)
{
temp1=temp1->next;
}
temp1->next->pre=temp;
temp->next=temp1->next;
temp->pre=temp1;
temp1->next=temp;
}
}

void display(struct node *t)
{
struct node *temp;
if(t==NULL)
{
printf("link list empty");
}
else
{
temp=t;
while(temp->next!=NULL)
{
printf("%d",temp->data);
temp=temp->next;
}
}
}
void delfirst(struct node *st)
{
if(st==NULL)
{
printf("link list empty");
}
else
{
struct node *temp;
temp=st;
temp->pre->next=temp->next;
st=temp->next;
temp->next->pre=temp->pre;
}
}
this is the program made by me please see and tell me the errors
Dec 4 '07 #9
Mark Bluemel wrote:

Oh! and main returns int - I fixed it in my version but forgot to
mention it. (Ideally I should have used "int main(void)")
Dec 4 '07 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Christopher Pisz | last post: by
1 post views Thread by Wayne Aprato | last post: by
8 posts views Thread by sudhirlko2001 | last post: by
3 posts views Thread by Imran Aziz | last post: by
2 posts views Thread by Rune Froysa | last post: by
3 posts views Thread by A_Republican | last post: by
4 posts views Thread by lokki | last post: by
reply views Thread by kmladenovski | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.