before encountering a dictionary tree or a pointer linked list, or directly on the list.
Array list the main ideas and pointers are similar.
A pointer is a *next that records the next address and then forms a chain.
The array itself is an address when it opens up space, so this can be achieved.
such as int a[11]; A[0]=1; a[1]=2; a[2]=4; a[4]=3;
a[a[0]]=a[1]=2 This achieves the 1 2 4 3 to be received together.
Carefully analyze the subscript of array A to increase, but the recorded data is updated.
So you can write roughly
int next[11];
int now=0; Cursor
for (int i=1;i<=n;i++)
{
Next[i]=next[now]; Update data
Next[now]=i; Record location
now++; Cursor movement
}
Different topic cursor jumping way different, now on the example
Little Violet Book UVA 11988
Enter a string of characters (space with ' _ ' instead of) where the character ' [' means that the ' home ' (cursor moves to the front) character '] ' represents the end key (the cursor moves to the last) output after the run of the string (length 100000);
Sample Input This_is_a_[beiju]_text
Sample Output Beijuthis_is_a_text
Get the title if the string length is small, you can simulate the violence directly.
However, if the string length is 100000, if you insert a number to the front, you move backwards so that the amount of time is large (the system doesn't want to talk to you and throws you a tle)
So we're going to use the linked list.
The difference is that the cursor may jump to the front or the last face, so set a variable to record the current last position.
The code is as follows
#include <stdio.h>
#include <string.h>
#define MAX 100000
int main ()
{
Char s[max+5];
int next[max+5];
int now;
while (~SCANF ("%s", s+1)//0 bits starting from 1th bit
{
memset (Next,0,sizeof (next));
int i,ed=0; Set the current last position to 0
now=0; Initialize cursor
For (I=1;i<=strlen (s+1); i++)
{
if (a[i]== ' [') now=0; Move the cursor to the front
else if (a[i]== '] ') now=ed; Cursor moves to the last
else {
Next[i]=next[now]; Update Next Array
Next[now]=i;
if (Ed==now) ed=i; Update the last digit
Now=i; Update cursor
}
for (I=next[0];i!=0;i=next[i])
printf ("%c", S[i]);
printf ("\ n");
]
}
UVA 11988 Linked List