-
Go to your teacher to help you out.
These have already been returned to the teacher.
-
Once the array is defined, the size cannot be changed, but the array can be accessed randomly, as long as the subscript is written, the linked list can be flexibly increased in length in the case of frequent random access to data, only the pointer needs to point to the next element, but when accessing the data, you need to find it from the beginning, suitable for traversal and so on.
-
It is the head node (head) that is buckled
The car is the first node (first son).
The horse is the secondary node (second son).
The toothpick is thin with a pointer, the black one is pointing, and the iron head is pointing with a thin head.
The following is the while loop (condition: the incense head points not to be empty) the first loop brings the horse to the front of the cart, and the second cycle brings the phase to the front of the horse.
The third cycle brings the taxi to the front of the phase.
Stop the loop until the incense point is empty.
**As follows: Only one first node phead is needed to find the linked list and invert it. The details are as follows.
pxiang = phead->pnext;
P iron = P incense - > pnext;
p->pnext=null;
P incense = P iron.
While (P incense ! =null)
P iron = P incense - > pnext;
p->pnext=phead->pnext;
phead->pnext=pfragrance;
P incense = P iron.
Compared with the pseudo-algorithm (three steps and four cycles), it is a one-to-one correspondence with the ** above:
Step 1: The incense head points to the first son, and the iron head points to the second son.
Step 2: Delete the toothpick that points to the second son (the one pointed by the iron head) Step 3: The incense head follows the iron head.
The following cycle conditions: (Condition: incense head pointing is not empty).
Cycle 4: The incense head follows the iron head.
Operate with props a few times, and then memorize the process, and then write ** according to the process in the future.
-
lead singly linked list p = head->next ; head->next = 0 ;while(p) is now reversed.
-
#include ""
#include"" typedef struct nodelink;link *creat(int n) create linked list p->next=null;
return head;
void reverse(link *head) s->next=p;
head->next->next=null;Closing head->next=s; Heading.
void display(link *head) displays the contents of the linked listprintf("");
void main()
-
#include
#include
#include
#include
#define list_init_length 10
#define ok 1
typedef int elemtype;
typedef struct cirlnode
cirlnode,*cirlinklist;
Construct a singly linked list l
end of for
/end of createlist_l() function
Invert the singly linked list and return ok
while ends.
l= t;//
return ok;
/ contray_cirl
void main() main() function.
contray_cirl(l);
cout<<"The reversed singly linked list l is as follows:"cout//end of main() function
-
It is advisable to draw a link to indicate intent to assist in understanding.
void reverse(struct node *head) At this point, s->next == null, and the loop ends.
s->next = p;Flip the last node head->next->next = null; The node pointed to next in the head is the first data node of the original linked list.
head->next = s;Now s is the new first data node}
-
number *s,*r;A temporary pointer char x that defines two linked list types; define a temporary inverselist(number); Call the inverted linked list cout<<"The inversion of this linked list is:"<
-
#include""
#include""
typedef int elementype;
#define maxsize 100
struct list
elementype *elem;
int length;
int listsize;
Create a linked list. int initlist(list *l)int i=0,x;
l->elem=(elementype *)malloc(sizeof(elementype));
if(!l->elem)
cout<<"Failed to establish a linked list"l->listsize=maxsize;
while(1)
cout<<"Please enter the linked list data:";
cin>>x;
if(x==0) break;
l->elem[i]=x;
l->length++;
i++;return 1;
int swaplist(list *l)int i=0,k,t;
k=(int)(l->length/2);
for(i=0;ielem[i];
l->elem[i]=l->elem[l->length-1-i] ;
l->elem[l->length-1-i]=t;
return 1;
int displaylist(list *l)int i=0;
cout<<"The linked list data is:"coutlist *l;
initlist(l);
displaylist(l);
swaplist(l);
displaylist(l);
return 1;
-
This I will write in the cave! There have been similar writes about Na Tease before,
-
A hashmap is actually a combination of an array and a linked list.
In a data structure, this is commonly referred to as a "linked list hash").
Hope it helps!
-
The method is very simple, and it can be achieved by using the idea of head insertion in the algorithm of generating a single linked list!
1. First disconnect the first node and the rest of the nodes;
2. Then remove the remaining nodes in turn and always insert them after the first node. That's it.
-
The time complexity is o(n), n is the number of nodes in the linked list, when reversed, the algorithm idea is to pick off the nodes in the original table in turn along the chain and insert them into the header of the new table, so the while loop in the algorithm will execute n trips, and then according to the algorithm we calculate t(n), t(n)=2+4*n+1+1. Explain the origin of this equation, 2 refers to the two basic operations before the while loop, 4*n is the while loop to execute n times, there are 3 basic operations and 1 loop judgment operation in the loop body in each loop, and the next two 1s, the previous 1 means that there is still 1 loop judgment after the last cycle, and the latter 1 refers to the return operation. So t(n)=4n+4, then o(t(n))=o(4n+4)=o(4n)=o(n).
One. Normal work cannot achieve financial freedom, and can only maintain a minimum of well-off life. Because in the company's revenue share, the share of the part-time worker is actually very small, especially in the current situation where there are so many unemployed people, the average person's human resources are not valuable. >>>More
This major belongs to the engineering category, but the artistic color is also very strong, and those who do not have a painting foundation can also go to learn, although it is an engineering major, but after graduation, according to personal preferences and abilities, it is easy to find a job as a fashion designer after graduation, and it is easier to find a job in all levels of clothing after graduation. >>>More
People have dreams, with dreams to chase, success or not have to try, do a line of love, can not let themselves ruin life, everything is difficult at the beginning, as long as you insist on victory, don't be afraid of losing, to move forward bravely, to have a plan to act, step by step to do a good job, even if you fail do not regret, because you have worked hard, it is rare for people to have a fixed career in their lives, it is rare to have a dream, can not wait only to move forward, do not retreat when encountering difficulties, to calm down and think calmly, In this way, we can solve one difficulty after another, from small to big, from weak to strong, to believe in their own line, once also started a business, failed, this time we have to rely on heaven and earth to rely on the Bodhisattva, I hope this time to let myself run from time to time, so that the good luck can stand on my side, and use what I have learned in practice, say goodbye to pain, usher in happiness, and let myself be able to do my part for this big family. It allows parents to live happily ever after. >>>More
How to build an automatic business is very important and very necessary for entrepreneurs and business operators, once you create an automatic field, you will be very relaxed. >>>More