PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > linux.debian.user > with C algorythm (find unique value in an array) could you please make changes
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
linux.debian.user debian-user@lists.debian.org.

with C algorythm (find unique value in an array) could you please make changes

Réponse
 
LinkBack Outils de la discussion
Vieux 21/01/2007, 23h20   #1
Jabka atu
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut with C algorythm (find unique value in an array) could you please make changes

Good evening to all,...
i wrote a small algorythm (in C ) to find how many uniqe value are in an
array ..
then change the size of the array to store all the unique values ..

code you please look at the code and make changes to it (to)
/*
This program Should find the true length of an array (the number of
uniqe values)
then create a new array and copy all the unique values onto it.
It is relased with the GNU licence
Created by Jabka Atu (mashrom{dot}head{shift and 2 aka at}gmail.com)
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int truelength(int *arr,int *temp,int size){
int i=0,j,e=1,n=0;
//temp=(int *) malloc(sizeof(int)*size);
temp[0]=arr[0];
while(i<size){
for(j=0;j<n;j++)
if(arr[i]==temp[j])
{
e=0;
}

if(e==1)
{
temp[n]=arr[i];
n++;
}
i++;
e=1;

}
//This will shrink the corrct amount of mem ..
temp=realloc(temp,sizeof(int)*n);


return n;
}

int main(){
int i,e,n,j,size,*ptr,*temp,*newarry;
printf("Please enter the size ");
scanf("%d",&size);
ptr=(int *) malloc(sizeof(int)*size);
for(i=0;i<size;i++)
scanf("%d",&ptr[i]);
temp=(int *) malloc(sizeof(int)*size);
n=truelength(ptr,temp,size);
printf("The size of the array %d",n);

for(i=0;i<n;i++)
printf("%d ",temp[i]);
free(temp);
free(ptr);
return 0;
}




--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Réponse avec citation
Vieux 22/01/2007, 01h00   #2
Ron Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with C algorythm (find unique value in an array) could you please make changes

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 01/21/07 17:18, Jabka atu wrote:
> Good evening to all,...
> i wrote a small algorythm (in C ) to find how many uniqe value are in an
> array ..
> then change the size of the array to store all the unique values ..
>
> code you please look at the code and make changes to it (to)
> /*
> This program Should find the true length of an array (the number of
> uniqe values)
> then create a new array and copy all the unique values onto it.
> It is relased with the GNU licence
> Created by Jabka Atu (mashrom{dot}head{shift and 2 aka at}gmail.com)
> */


This smells like CompSci homework.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFFtAtUS9HxQb37XmcRAoZ5AKCzNzudKa51OWL73YNspt Hs/SDuwQCfTuWZ
6Q4OIG8C+nQCV1/eFYTmHG8=
=ylZC
-----END PGP SIGNATURE-----


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Réponse avec citation
Vieux 22/01/2007, 02h20   #3
Roberto C. Sanchez
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with C algorythm (find unique value in an array) could you please make changes

On Sun, Jan 21, 2007 at 06:54:44PM -0600, Ron Johnson wrote:
> On 01/21/07 17:18, Jabka atu wrote:
> > Good evening to all,...
> > i wrote a small algorythm (in C ) to find how many uniqe value are in an
> > array ..
> > then change the size of the array to store all the unique values ..
> >
> > code you please look at the code and make changes to it (to)
> > /*
> > This program Should find the true length of an array (the number of
> > uniqe values)
> > then create a new array and copy all the unique values onto it.
> > It is relased with the GNU licence
> > Created by Jabka Atu (mashrom{dot}head{shift and 2 aka at}gmail.com)
> > */

>
> This smells like CompSci homework.
>

<g>

I was thinking the same thing.

Regards,

-Roberto

--
Roberto C. Sanchez
http://people.connexer.com/~roberto
http://www.connexer.com

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFFtB6k1snWssAFC08RArCeAKCFm1BA2IRGprXJcimv3N KtBfP5PQCdFfcL
00sbegueT5CjrG+VMmtATo4=
=oA24
-----END PGP SIGNATURE-----

  Réponse avec citation
Vieux 22/01/2007, 10h40   #4
Jon Dowland
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with C algorythm (find unique value in an array) could you please make changes

On Sun, Jan 21, 2007 at 09:17:08PM -0500, Roberto C. Sanchez wrote:
> On Sun, Jan 21, 2007 at 06:54:44PM -0600, Ron Johnson wrote:
> >
> > This smells like CompSci homework.
> >

> <g>
>
> I was thinking the same thing.


I think it's our duty to provide the most cunning/evil solution possible
then


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Réponse avec citation
Vieux 22/01/2007, 14h20   #5
Roberto C. Sanchez
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with C algorythm (find unique value in an array) could you please make changes

On Mon, Jan 22, 2007 at 10:30:29AM +0000, Jon Dowland wrote:
> On Sun, Jan 21, 2007 at 09:17:08PM -0500, Roberto C. Sanchez wrote:
> > On Sun, Jan 21, 2007 at 06:54:44PM -0600, Ron Johnson wrote:
> > >
> > > This smells like CompSci homework.
> > >

> > <g>
> >
> > I was thinking the same thing.

>
> I think it's our duty to provide the most cunning/evil solution possible
> then


Yes, well I don't think that recommending he redo the homework in Lisp
from within Emacs is very nice. Maybe we should recommend Visual J#?

/ducks

:-)

Regards,

-Roberto

--
Roberto C. Sanchez
http://people.connexer.com/~roberto
http://www.connexer.com

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFFtMZo1snWssAFC08RAhKtAJ9i/pgoh28jEaWg8pmehhoAAbOBTACeIEfb
5be/YNDU29j4M+8to5PSGcU=
=32E5
-----END PGP SIGNATURE-----

  Réponse avec citation
Vieux 22/01/2007, 14h40   #6
Ron Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with C algorythm (find unique value in an array) could you please make changes

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 01/22/07 08:12, Roberto C. Sanchez wrote:
> On Mon, Jan 22, 2007 at 10:30:29AM +0000, Jon Dowland wrote:
>> On Sun, Jan 21, 2007 at 09:17:08PM -0500, Roberto C. Sanchez wrote:
>>> On Sun, Jan 21, 2007 at 06:54:44PM -0600, Ron Johnson wrote:
>>>> This smells like CompSci homework.
>>>>
>>> <g>
>>>
>>> I was thinking the same thing.

>> I think it's our duty to provide the most cunning/evil solution possible
>> then

>
> Yes, well I don't think that recommending he redo the homework in Lisp
> from within Emacs is very nice.


Not a bad idea, actually.

Other good languages for implementation:

GW-BASIC
FORTRAN IV
COBOL 66
FORTH

> Maybe we should recommend Visual J#?


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFFtMweS9HxQb37XmcRAksoAJ41kxRZOcXftFiK2X6xPE a7G7J5/wCgkGO/
HJtq5z2SpSNhtSG8eki1QH0=
=Ilot
-----END PGP SIGNATURE-----


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
  Réponse avec citation
Vieux 22/01/2007, 17h10   #7
Roberto C. Sanchez
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with C algorythm (find unique value in an array) could you please make changes

On Mon, Jan 22, 2007 at 11:36:11AM -0500, Kamaraju Kusumanchi wrote:
>
> Hey guys
> Lighten up! Give him the benefit of doubt and him if you can. May be
> the OP belongs to some other field and is trying to get a sense of algorithm
> implementation for a related problem.
>

Except that:

* He is asking a question that can be reasonably answered after reading
a decent introductory CompSci text
* He is coding in C (if he really works in another field, it is
*highly* unlikely that he would be working in C; Matlab would be more
likely)
* He is asking people on the list to modify the code for him
* He provides no indication of what due dilligence he has taken up to
now

> Mocking/rediculing others is not a good idea (especially on public lists)!
>

It is not mocking or ridicule. Simply, someone commented that it
smelled like CompSci homework and some snarky comments were made.
Nobody called him a loser or used any sort of negative language toward
him.

Regards,

-Roberto

--
Roberto C. Sanchez
http://people.connexer.com/~roberto
http://www.connexer.com

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFFtO4s1snWssAFC08RAs9yAKCXHAH4udl/DMvfUMEZ5mGYYu+gsACfSlGA
9qMxn52fW8bEISX2dD8ERE8=
=MBMU
-----END PGP SIGNATURE-----

  Réponse avec citation
Vieux 22/01/2007, 17h30   #8
Jon Dowland
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: with C algorythm (find unique value in an array) could you please make changes

On Mon, Jan 22, 2007 at 10:30:29AM +0000, Jon Dowland wrote:
> I think it's our duty to provide the most cunning/evil
> solution possible then


Probably not all that evil or cunning by most people's
standards, but here's my solution. I tried to do a
continuation-passing-style tail recursive thing, but my C
skills aren't up to it.


--
Jon Dowland

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 23h22.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,17617 seconds with 16 queries