Incorporate another function into this problem C++

  • Thread starter Thread starter heavyc
  • Start date Start date
  • Tags Tags
    C++ Function
AI Thread Summary
The discussion revolves around incorporating an additional function into a C++ program that manipulates a linked list. The user is attempting to integrate a nested loop structure for traversing the list and conditionally unlinking nodes based on comparisons. There is confusion regarding variable definitions and their placements within the existing code structure. The goal appears to be either creating a new list or removing specific nodes from the original list. Clarification is needed on the intended functionality of the new code segment to ensure proper integration.
heavyc
Messages
16
Reaction score
0
i have this problem and i am having trouble how to incorporate another function into this problem here is the problem..

#include <iostream>

using namespace std;

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

struct node *push_front ( node *list, int data )
{
node *p = new node;

p->data = data;
p->next = list;
list = p;

return list;
}

int main()
{
node *list = 0;
node *save;

for ( int i = 0; i < 10; i++ )
list = push_front ( list, rand() % 5 + 1 );

while ( list != 0 ) {
save = list->next;
cout<< list->data <<' ';
delete list;
list = save;



}

cout<<'\n';
}

and here is what i am trying to put in.., i have it written but i don't know what varibles to put and where to put it into the program..

for ( i = first; i != last; i = next ( i ) ) {
for ( j = next ( i ); j != last; j = next ( j ) ) {
if ( i == j )
unlink ( j );
}
}
 
Physics news on Phys.org
Right up to the last part:
heavyc said:
for ( i = first; i != last; i = next ( i ) ) {
for ( j = next ( i ); j != last; j = next ( j ) ) {
if ( i == j )
unlink ( j );
}
}
makes sense (except for a few minor problems), but nobody on Earth understands this last part. What are you trying to do with this part of the code? It seems you are travesing a new type of linked list (with the first and last nodes named) and at some node (j) you want to break the list into a new list or either cut the node (j) out of the original list.
 
I multiplied the values first without the error limit. Got 19.38. rounded it off to 2 significant figures since the given data has 2 significant figures. So = 19. For error I used the above formula. It comes out about 1.48. Now my question is. Should I write the answer as 19±1.5 (rounding 1.48 to 2 significant figures) OR should I write it as 19±1. So in short, should the error have same number of significant figures as the mean value or should it have the same number of decimal places as...
Thread 'Minimum mass of a block'
Here we know that if block B is going to move up or just be at the verge of moving up ##Mg \sin \theta ## will act downwards and maximum static friction will act downwards ## \mu Mg \cos \theta ## Now what im confused by is how will we know " how quickly" block B reaches its maximum static friction value without any numbers, the suggested solution says that when block A is at its maximum extension, then block B will start to move up but with a certain set of values couldn't block A reach...
Thread 'Calculation of Tensile Forces in Piston-Type Water-Lifting Devices at Elevated Locations'
Figure 1 Overall Structure Diagram Figure 2: Top view of the piston when it is cylindrical A circular opening is created at a height of 5 meters above the water surface. Inside this opening is a sleeve-type piston with a cross-sectional area of 1 square meter. The piston is pulled to the right at a constant speed. The pulling force is(Figure 2): F = ρshg = 1000 × 1 × 5 × 10 = 50,000 N. Figure 3: Modifying the structure to incorporate a fixed internal piston When I modify the piston...

Similar threads

Replies
1
Views
10K
Replies
3
Views
2K
Replies
1
Views
1K
Replies
2
Views
1K
Replies
10
Views
2K
Replies
3
Views
8K
Replies
5
Views
2K
Replies
25
Views
2K
Back
Top