-
void combine (node *head1,node *head2){node*p; &47;/temporary pointer p head1; &47;/The header node that points to the first linked list while (null !) =p) && (null !=p->next)) 47;/p is not empty, p gt; next is also not empty 47;/If p is empty, it means that the first linked list has exception 47;/If p gt; next is empty, it means that the end of the linked list has been reached. { p p gt; next; }47;/Point the end of the first linked list to the first node of the second linked list, i.e. exclude the header node p gt; next = head2->next;Write so much for the time being, in fact, you have to judge whether head2 is empty, you can improve it yourself, it's good to know the thought, don't know how to ask.
-
You understand:
In the nodes described by the data structure, p->next has two meanings, one is the address value of the successor node stored in the next domain of the current node, and the second is the direct successor node that describes the current node.
-
Including the creation, deletion, addition and release of linked lists!!
#include
#include
struct node *create();
void print_list(struct node *head);
struct node * insert_node(struct node *h,int x,int y);
struct node * delete_node(struct node *h,int z);
void shifang(struct node *head);
struct node
void main()
struct node *create() to create a linked list function.
The pointer field of the tail node is assigned null
tail->next=null;
return head;
void print list(struct node *head) outputs a linked list function.
printf("end.");}
struct node * insert node(struct node *h,int x,int y).
Insert the node. q->next=s;s->next=p;
return(h);
struct node * delete node(struct node *h,int z) deletes the node function.
Release the node. if(p->data ==z)
return(h);
void shifang(struct node *head) releases the linked list function}
-
There are many operations on linked lists, such as creating, inserting, sorting, deleting, and exporting. What exactly does the landlord want to ask?
-
The linked list in C is a data structure, a linear storage structure.
Like arrays, linked lists are also a data structure that organizes a set of data of the same type together, but arrays are stored sequentially, relying on the first address of the array and the relative address of the element (subscript) to achieve access. The advantage is that it is easy to access, while the disadvantage is that the array is static, which is not conducive to the dynamic addition and deletion of elements. Linked lists, on the other hand, use discrete storage and rely on pointers between nodes to the next node for access.
Its advantages and disadvantages are the opposite of arrays.
There can be different types of data in a linked list.
-
Note which node the head points to each time.
head->next always points to the last node that has been inverted, i.e. the new inverted head node.
Therefore, every time you complete the inversion of a new node, you need to point its next to the previous inverted node, which happens to be the node that head-> next points to.
For example, there are linked lists a->b->c->d->null
Start head->next = a, head->next->next=b
First let p=a, and let a->next=null, i.e. make a the tail node.
Then q points to b, and head->next still points to a, that is, the node that has just completed the inversion.
while starting.
Assign q to p each time, so p=b, q =c, b->next=head->next = a, head-next = b
At this time, head->next points to b, which happens to be the node that has just completed the inversion.
Continue the cycle later.
-
void combine (node *head1,node *head2)
Point the end of the first linked list to the first node of the second linked list, i.e. exclude the head node p->next = head2->next;
Let's write so much for the time being, in fact, you have to judge whether head2 is empty or not, you can improve it yourself, and it would be good to know the thoughts.
I don't know how to ask again.
-
The function of this function is to store the num value in a new node, which is attached to the tail of the linked list.
void ins_list( pnode head, int num )
p->data = num;Store the value to be inserted into the dynamic node, p->next = head->next; Connect the new node to the linked list.
head->next = p;
The above two sentences are a bit of a bit"Winding"。With the while() loop, head->next is already null
The following two lines can also be used to connect the new node to the linked list: head->next = p;
p->next = null;}
-
current is not defined, are you writing it wrong, that's right, just send it all.
-
Directly entering the linked list as empty will cause an error, so let's not talk about this.
The reverse linked list function is modified as follows:
void reverse(node *&head)head=p1;The head node is the first node}
-
void destroy(node *&head);What type of parameter does your function define and how is it a reference and a pointer?
-
:head=head;
It doesn't seem to work.
The head in the delete function is changed from the subfunction and returned to the original after the deletion function, and the following is the modified program:
#include
using namespace std;
class node
public:
int date;Data domains.
node*next;Pointer field.
node *head;Define global pointers.
node*create() to create a linked list function.
node *p1,*p2;
p1=new node;
cin>>p1->date;
p2=p1;
head=p1;
while (p1->date!=0)
p1=new node;
cin>>p1->date;
p2->next=p1;
p2=p1;
p2->next=null;
delete p1;
return head;
void print(node*head) prints the linked list function.
while (head)
coutnext;
void delete_member(node **phead,int number)
int x=2;
node *p1;
node *p2;
if (number==1)
p1 = p2 =*phead);
p1=p1->next;
phead) =p1;
delete p2;
return;
elsewhile (number>x)
head=head->next;
x++;p1=head->next;
head->next=head->next->next;
delete p1;
return;
void main()
node*head=create();
print(head);
delete_member(&head,1);
print(head);
system("pause");
The results are shown in the figure.