Collection operation

zhaozj2021-02-16  50

#define len sizeof (struct order)

#include

Struct ORDER

{char NUM;

Struct Order * Next;

}

void main ()

{INT I, J;

Char P1 [30], P2 [30];

Struct Order * B, * BPRE, * BHEAD, * A, * APRE, * AHEAD, * P;

Printf ("/ NENTER THE FIRST CHARS:");

Gets (p1);

Order (P1, Strlen (P1));

Printf ("/ NENTER THE Second Chars:");

Gets (p2);

Order (P2, Strlen (P2));

A = apre = (struct order *) malloc (len);

For (i = 0; i

IF ((p1 [i]> = 'a') && (p1 [i] <= 'z')))

Break;

A-> Num = p1 [i];

Ahead = a;

For (j = i 1; j <= Strlen (p1); J )

{a = (struct order *) malloc (len);

While (p1 [j-1] == p1 [j])

J = J 1;

A-> Num = p1 [j];

Apre-> next = a;

APRE = a;

}

A-> Next = 0;

a = ahead;

B = bpre = (struct order *) malloc (len);

For (i = 0; i

IF ((p2 [i]> = 'a') && (p2 [i] <= 'z')))

Break;

B-> Num = p2 [i];

BHEAD = B;

For (j = i 1; j <= strlen (p2); J )

{b = (struct order *) malloc (len);

While (p2 [j-1] == p2 [j])

J = J 1;

B-> Num = p2 [j];

BPRE-> next = B;

BPRE = B;

}

B-> next = 0;

B = bhead;

Printf ("" The P1UP2 IS: ");

While (a-> next! = 0 && b-> next! = 0) // Judgment panel pay attention to the movement of the pointer

{IF (A-> Num == B-> Num)

{Printf ("% C", A-> Num);

a = a-> next;

B = b-> next;}

IF (A-> Num Num)

{Printf ("% C", A-> Num);

a = a-> next;}

IF (A-> Num> B-> Num)

{Printf ("% C", b-> num);

B = b-> next;}

}

While (A-> Next! = 0) // Is there a situation in A, B

{Printf ("% C", A-> Num);

a = a-> next;}

While (B-> Next! = 0) {Printf ("% C", B-> Num);

B = b-> next;}

a = ahead; b = bhead;

Printf ("/ NTHE P1% CP2 IS:", 239); //

While (A-> Next! = 0 && B-> Next! = 0)

{IF (A-> Num == B-> Num)

{Printf ("% C", A-> Num);

a = a-> next;

B = b-> next;

}

IF (A-> Num Num)

a = a-> next;

IF (A-> Num> B-> Num)

B = b-> next;

}

a = ahead; b = bhead;

Printf ("/ NTHE P1-P2 IS:");

While (a-> next! = 0 && b-> next! = 0) // Note the move of the a pointer

{IF (A-> Num == B-> Num)

{P = a;

a = a-> next;

B = b-> next;

IF (p == ahead)

Ahead = a;

Else

Apre-> next = a;

Free (p);

}

IF (A-> Num Num)

{APRE = a;

a = a-> next;

}

IF (A-> Num> B-> Num)

B = b-> next;

}

a = ahead;

While (A-> Next! = 0)

{Printf ("% C", A-> Num);

a = a-> next;

}

a = ahead; b = bhead;

Getch ();

}

Order (CHAR A [15], INT N) / / Sort by string

{INT I, J, K;

CHAR T;

For (i = 0; i

{k = i;

For (j = i 1; j

IF (a [j] <= a [k]) k = j;

T = a [k]; a [k] = a [i]; a [i] = t;

}

}

Summary: Sort in strings, the same removed, then enter the list

转载请注明原文地址:https://www.9cbs.com/read-22800.html

New Post(0)