how to find a variable in a given list and replace/delete them according to our wish

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nayeef
    New Member
    • Sep 2006
    • 3

    how to find a variable in a given list and replace/delete them according to our wish

    hello there
    i want to know a program which will find find a given variable in a list and replace/delete them according to our wish. Well it would be preferable if its in C.
    thanks
  • pukur123
    New Member
    • Sep 2006
    • 61

    #2
    Have you gone through the program for the deletion of a node in a linked list? If you done this program then you can solve the problem.

    Comment

    • nayeef
      New Member
      • Sep 2006
      • 3

      #3
      Originally posted by pukur123
      Have you gone through the program for the deletion of a node in a linked list? If you done this program then you can solve the problem.
      can you atleast tell me the link for that program..its pretty exhaustive in here..it would be highly appreciated..al so i want to do this in a structure instead of a linked list..guess that will be possible
      thanks
      nayeef

      Comment

      • pukur123
        New Member
        • Sep 2006
        • 61

        #4
        Then you are talking about the array of structures.

        See in an array you can not delete an element. The thing you can do is that you can replace a particular element or you simply left shift all the elements.

        Comment

        • ssehgal2010
          New Member
          • Aug 2006
          • 10

          #5
          hi Nayeef below is the code which I wrote long back for finding a number in a list and replacing desired one
          this is C code only using linked list.

          #include <stdio.h>
          #include <stdlib.h>
          #include <string.h>
          #define EXITSUCC 1;
          #include <conio.h>

          void push(struct node** , int i );
          void insert(struct node** , int , int );

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


          void main()
          {
          int i;
          struct node* head = malloc(sizeof(s truct node));
          struct node* ptr = malloc(sizeof(s truct node));
          struct node* temp = malloc(sizeof(s truct node));
          clrscr();

          push(&head,0);
          ptr = head;
          for(i=1;i<=8;i+ +){
          push(&(head->next),i);
          head = head->next;
          }

          //storing for future use here....
          temp = ptr;

          while(ptr != NULL ){
          printf("\n%d",p tr->data);
          ptr = ptr->next;
          }

          printf("\n..... Want to insert data here.........\n ");
          insert(&temp,56 ,5);
          printf("\n..... ....After Insert operation...... ..\n");
          while(temp != NULL ){
          printf("\n%d",t emp ->data);
          temp = temp ->next;
          }


          getch();
          }

          void push(struct node** str,int data){

          struct node* temp = malloc(sizeof(s truct node));

          temp -> data = data;
          temp -> next = NULL;
          *str = temp;

          }

          void insert(struct node** str, int n,int old){

          struct node* temp = malloc(sizeof(s truct node));
          struct node* new1 = malloc(sizeof(s truct node));

          temp = *str;
          while( temp!= NULL ){
          if(temp->data == old){
          new1 -> next = temp -> next;
          new1 -> data = n;
          temp -> next = new1;
          return;
          }
          temp = temp->next;
          }

          }

          Comment

          • nayeef
            New Member
            • Sep 2006
            • 3

            #6
            Thanks a lot sehgal and pukur.Your tips were indeed handy
            Regards
            Nayeef

            Comment

            Working...