PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.c > list reverse function
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
list reverse function

Réponse
 
LinkBack Outils de la discussion
Vieux 16/10/2007, 20h28   #1 (permalink)
lovecreatesbea...@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut list reverse function

Reverse a single directional non-circle list. For example:

p | p
| | |
+-+-+ +---+ +---+ +---+ | +---+ +---+ +---+ +-+-
+
| 1 | -> | 2 | -> | 3 | -> | 4 | | | 1 | <- | 2 | <- | 3 | <- | 4
|
+---+ +---+ +---+ +---+ | +---+ +---+ +---+ +---
+

Comments are welcome.


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

struct node list_rvs(struct node p)
{
struct node p1 = p, p2 = p->next, p3;

while (p2){
p3 = p2->next;
p2->next = p1;
p1 = p2;
p2 = p3;
}
p->next = 0;
p = p1;
return p;
}

  Réponse avec citation
Vieux 16/10/2007, 20h41   #2 (permalink)
Eric Sosman
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: list reverse function

lovecreatesbea...@gmail.com wrote On 10/16/07 15:28,:
> Reverse a single directional non-circle list. For example:
>
> p | p
> | | |
> +-+-+ +---+ +---+ +---+ | +---+ +---+ +---+ +-+-
> +
> | 1 | -> | 2 | -> | 3 | -> | 4 | | | 1 | <- | 2 | <- | 3 | <- | 4
> |
> +---+ +---+ +---+ +---+ | +---+ +---+ +---+ +---
> +
>
> Comments are welcome.


What comments did your compiler offer when you
asked it (politely) to review your code?

> struct node {int data; struct node next;};
> [...]


'nuff said.

--
Eric.Sosman@sun.com

  Réponse avec citation
Vieux 16/10/2007, 21h02   #3 (permalink)
Richard
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: list reverse function

"lovecreatesbea...@gmail.com" <lovecreatesbeauty@gmail.com> writes:

> Reverse a single directional non-circle list. For example:
>
> p | p
> | | |
> +-+-+ +---+ +---+ +---+ | +---+ +---+ +---+ +-+-
> +
> | 1 | -> | 2 | -> | 3 | -> | 4 | | | 1 | <- | 2 | <- | 3 | <- | 4
> |
> +---+ +---+ +---+ +---+ | +---+ +---+ +---+ +---
> +
>
> Comments are welcome.
>
>
> struct node {int data; struct node next;};
>
> struct node list_rvs(struct node p)
> {
> struct node p1 = p, p2 = p->next, p3;
>
> while (p2){
> p3 = p2->next;
> p2->next = p1;
> p1 = p2;
> p2 = p3;
> }
> p->next = 0;
> p = p1;
> return p;
> }


You need to examine the use of structures versus pointers to structures.

Did you compile this?
  Réponse avec citation
Vieux 16/10/2007, 22h11   #4 (permalink)
Peter Pichler
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: list reverse function

lovecreatesbea...@gmail.com wrote:

> Reverse a single directional non-circle list.


Is that an order?

> Comments are welcome.


Comments on what? Your code does not compile because you miss asterisks
all over the place. As others suggested, you would have known that
yourself had you bothered to compile before posting. Fix the syntax
errors and your homework is done. Where did you copy it from, just out
of interest? The algorithm looks OK, suggesting a level of understanding
that makes the absence of asterisks rather surprising.
  Réponse avec citation
Vieux 17/10/2007, 03h24   #5 (permalink)
lovecreatesbea...@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: list reverse function

On Oct 17, 4:02 am, Richard <rgr...@gmail.com> wrote:
> "lovecreatesbea...@gmail.com" <lovecreatesbea...@gmail.com> writes:
> > Reverse a single directional non-circle list. For example:

>
> > p | p
> > | | |
> > +-+-+ +---+ +---+ +---+ | +---+ +---+ +---+ +-+-
> > +
> > | 1 | -> | 2 | -> | 3 | -> | 4 | | | 1 | <- | 2 | <- | 3 | <- | 4
> > |
> > +---+ +---+ +---+ +---+ | +---+ +---+ +---+ +---
> > +

>
> > Comments are welcome.

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

>
> > struct node list_rvs(struct node p)
> > {
> > struct node p1 = p, p2 = p->next, p3;

>
> > while (p2){
> > p3 = p2->next;
> > p2->next = p1;
> > p1 = p2;
> > p2 = p3;
> > }
> > p->next = 0;
> > p = p1;
> > return p;
> > }

>
> You need to examine the use of structures versus pointers to structures.
>
> Did you compile this?


Yes, it compiles without syntax error. The parameter and all local
variable are pointers. The asterisks were removed carelessly when I
did replacement. Thank you.

  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 11h31.


É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,12868 seconds with 13 queries