|
|
|
|
||||||
| linux.debian.user debian-user@lists.debian.org. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
-----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 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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----- |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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----- |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
-----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 |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
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----- |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
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 |
|
![]() |
| Outils de la discussion | |
|
|