deletion in link list

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ratika

    deletion in link list

    can anyone tell me how to delete a certain node in a doubly circular
    link list
  • Mark Bluemel

    #2
    Re: deletion in link list

    ratika wrote:
    can anyone tell me how to delete a certain node in a doubly circular
    link list
    Carefully...

    Comment

    • ravi

      #3
      Re: deletion in link list

      On Dec 3, 4:36 pm, ratika <cool_ratikagu. ..@rediff.comwr ote:
      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

      Comment

      • santosh

        #4
        Re: deletion in link list

        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?

        Comment

        • Chris Dollin

          #5
          Re: deletion in link list

          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

          Comment

          • Eric Sosman

            #6
            Re: deletion in link list

            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.programmin g">

            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
            esosman@ieee-dot-org.invalid

            Comment

            • Thomas X. Iverson

              #7
              Re: deletion in link list

              On Dec 3, 7:36 pm, ratika <cool_ratikagu. ..@rediff.comwr ote:
              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

              Comment

              • ratika

                #8
                Re: deletion in link list

                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.comwr ote:
                >
                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

                Comment

                • ratika

                  #9
                  Re: deletion in link list

                  On Dec 3, 4:36 pm, ratika <cool_ratikagu. ..@rediff.comwr ote:
                  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",&ite m);
                  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(si zeof(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",tem p->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

                  Comment

                  • Mark Bluemel

                    #10
                    Re: deletion in link list

                    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)")

                    Comment

                    Working...