473,386 Members | 1,819 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,386 software developers and data experts.

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;
}

Oct 16 '07 #1
3 1448
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.

--
Er*********@sun.com

Oct 16 '07 #2
"lovecreatesbea...@gmail.com" <lo***************@gmail.comwrites:
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?
Oct 16 '07 #3
On Oct 17, 4:02 am, Richard <rgr...@gmail.comwrote:
"lovecreatesbea...@gmail.com" <lovecreatesbea...@gmail.comwrites:
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.

Oct 17 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: M. Clift | last post by:
Hi All, Could someone help me out with this? items = ('a', 'b', 'c', 'd') items + 1 = ( 'b', 'c', 'd', 'a') items + 2 = ( 'c', 'd', 'a', 'b') items + 3 = ( 'd', 'a', 'b', 'c') trans = 1
41
by: Xah Lee | last post by:
here's another interesting algorithmic exercise, again from part of a larger program in the previous series. Here's the original Perl documentation: =pod merge($pairings) takes a list of...
20
by: xerix | last post by:
I'm trying to make a function which insert an object into a list and returns an iterator to the new element in the list. But as far as I know there is no function which returns an iterator to the...
19
by: RAJASEKHAR KONDABALA | last post by:
Hi, Does anybody know what the fastest way is to "search for a value in a singly-linked list from its tail" as oposed to its head? I am talking about a non-circular singly-linked list, i.e.,...
33
by: junky_fellow | last post by:
Consider a singly-linked list. Each node has a structure, struct node { char c; struct node *next; }; Each of the nodes contain an alphabetic character. Can anybody suggest a way to print...
25
by: Markus Svilans | last post by:
Hi, There seems to be some functionality missing from the STL. I am iterating through a linked list (std::list) using a reverse iterator and attempting to erase certain items from the list. It...
17
by: John Salerno | last post by:
Hi everyone. If I have a list of tuples, and each tuple is in the form: (year, text) as in ('1995', 'This is a citation.') How can I sort the list so that they are in chronological order based...
6
by: APEJMAN | last post by:
I know what I'm posting here is wired, but it's been 3 days I'm workin g on these codes, but I have no result I post the code here I dont wanne bother you, but if any one of you have time to...
36
by: pereges | last post by:
Hi, I am wondering which of the two data structures (link list or array) would be better in my situation. I have to create a list of rays for my ray tracing program. the data structure of ray...
2
by: torso | last post by:
Hi. I have a list. List should be indexed with id number, but how i can do it? Should I get list id's to array and use sort or is there better solutions for that? <ul id='List'> <li...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.