473,395 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

3
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
Sep 11 '06 #1
5 2479
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.
Sep 11 '06 #2
nayeef
3
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..also i want to do this in a structure instead of a linked list..guess that will be possible
thanks
nayeef
Sep 11 '06 #3
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.
Sep 11 '06 #4
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(struct node));
struct node* ptr = malloc(sizeof(struct node));
struct node* temp = malloc(sizeof(struct 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",ptr->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",temp ->data);
temp = temp ->next;
}


getch();
}

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

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

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

}

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

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

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

}
Sep 11 '06 #5
nayeef
3
Thanks a lot sehgal and pukur.Your tips were indeed handy
Regards
Nayeef
Sep 13 '06 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Xah Lee | last post by:
suppose you want to do find & replace of string of all files in a directory. here's the code: ©# -*- coding: utf-8 -*- ©# Python © ©import os,sys © ©mydir= '/Users/t/web'
19
by: rbt | last post by:
Here's the scenario: You have many hundred gigabytes of data... possible even a terabyte or two. Within this data, you have private, sensitive information (US social security numbers) about your...
11
by: Jonan | last post by:
Hello, For several reasons I want to replace the built-in memory management with some custom built. The mem management itlsef is not subject to my question - it's ok to the point that I have...
2
by: Philip WATTS | last post by:
I have generated a dynamic option list from an array using elementCreate("OPTION") I now wish to get an event to replace this list with a new one, but of course currently, it simply adds them on...
5
by: Bob | last post by:
Hi Everybody I hope you can help. 2 related questions. 1. I am looking for a way to replace the confusing message box that comes up when a user trys to open a form without putting data in...
25
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
3
by: Wijaya Edward | last post by:
Hi, How can we slurp all content of a single file into one variable? I tried this: <open file 'somefile.txt', mode 'r' at 0xb7f532e0>
0
by: 2Barter.net | last post by:
" Given BACK what was freely GIVEN " Inbox 2Barter.net Hide options 9:52 pm (0 minutes ago) From: 2Barter.net <chasingcowtomusic@gmail.com> Signed-By: gmail.com | Mailed-By: gmail.com Date:...
3
by: kingparthi | last post by:
This is a program to add, display & delete an item from the double linked list ... Here the add & display works correctly... where my delete is having some problem, when ever I delete an item, it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.