dev와 함께 마지막 노드와 첫 번째 노드의 위치를 바꾸려고합니다. ++는 내 성적에 대한 할당입니다.C++의 첫 번째 노드와 마지막 노드를 바꿔 넣습니다.
그리고 지금까지 내가 한 일은 다음과 같습니다. 나는 스왑 핑 기능을 시작하지 않았다.
#include <iostream>
#include <cstdlib>
using namespace std;
// Node class
class Node {
int data;
public:
Node* next;
Node(int d=0){
data = d;
next=NULL;
}
int getData() const{
return data;
}
}; //class Node
void display(Node *start, Node *end)
{
// Temp pointer
Node *tmp = start;
// One node in the list
while (tmp)
{
cout << tmp->getData() << "\t";
tmp=tmp->next;
}
} //display
Node* node;
int main()
{
Node *start, *end, *head, *last, *newNode;
start = end = new Node(5);
for (int n=10; n<=35; n=n+5) {
end->next=new Node(n);
end=end->next;
}
display(start,end);
cin.get();
//delete the first node
head=start;
start = start->next;
delete(head);
display(start,end);
cin.get();
//delete the last node
last = start;
end = start->next;
while(end->next != NULL){
last = end;
end = end->next;
}
last->next = NULL;
delete(end);
display(start,end);
cin.get();
//insert value 3 in front of the node
newNode = new Node(3);
newNode->next = NULL;
newNode->next = start;
start = newNode;
display(start,end);
cin.get();
//insert value 23 in between 20 and 25
int pos = 5;
newNode = new Node(23);
Node *temp;
end = start;
for(int i=1; i<pos-1; i++){
end = end->next;
}
temp = end->next;
end->next = newNode;
newNode->next = temp;
display(start,end);
cin.get();
//here is where the swap function must be performed.
display(start,end); //to display the result
cin.get();
} //main
불쌍한 사람, 크리스마스가 아닙니까? lol –
@FrederickZhang Procrastination. – LogicStuff
* 소녀. 나를위한 크리스마스는 없다. 결승전은 2 일 후입니다. 도와주세요. – beginner96