Main function Main.c
#include "func.h" #define MAXSIZE 100int32 Main (void) {INT32 Temp[maxsize] = {NULL}, f = 0, OSM = 1;OSM = CREATE_SL (tem P);d o{osm = osm_printf ("\n\t========================================\n"); OSM = osm_printf ("\t============= Select feature options: ============\n "), OSM = osm_printf (" \t===============1, insert Element ===============\n "); OSM = osm_printf (" \t===============2 , delete element ===============\n "), OSM = osm_printf (" \t===============3, append element ===============\n "); OSM = osm_printf (" \t======== =======4, get Element ===============\n "), OSM = osm_printf (" \t===============5, find Element ===============\n "); OSM = osm_printf (" \ t ===============6, emptying Element ===============\n "), OSM = osm_printf (" \t===============7, judging whether empty =============\n "); OSM = OSM_ Printf ("\t===============8, Judgment is full ===========\n"), OSM = osm_printf ("\t===============9, number of statistical elements =========\n"); OSM = osm_printf ("\t===============0, Exit ===================\n"); OSM = osm_printf ("\t**************** Select number *************** \ n "); f = scanf_for (); switch (f) {case 1:OSM = INSERT_SL (temp); Break;case 2:osm = DeleTE_SL (temp); Break;case 3:osm = ADD_SL (temp); Break;case 4:osm = GET_SL (temp); Break;case 5:osm = FIND_SL (temp); Break;cas E 6:OSM = CLEAR_SL (temp); Break;case 7:osm = EMPTY_SL (temp); Break;case 8:osm = FULL_SL (temp); Break;case 9:osm = number_s L (temp); Break;case 0:break;default:osm = osm_printf ("Input data is illegal!!!!") \ n "); break;}} while (0! = f); return 0;}
function function: FUNC.C
#include "func.h" #define MAXSIZE 100/* begin to limit the size of this order table */int32 CREATE_SL (INT32 a[])/* Create */{int32 OSM = 1, i32num = 0, i32 = 0;OSM = osm_printf ("Please enter the number of elements in the list to be created: \ n"); i32num = Scanf_for (); if ((0 > I32num) | | (MAXSIZE < I32num)) /* Created condition */{OSM = osm_printf ("illegal data \ n");} ELSE{OSM = osm_printf ("Input related element: \ n"); for (i32 = 0; i32 < i32num; i32++)/* INPUT element */{A[I32] = Scanf_for ();}} OSM = osm_printf ("Already created table \ n"); OSM = osm_printf ("table:"); for (i32 = 0; i32 < i32num; i32++)/* Print out */{if (NULL! = a[i32] ) {OSM = osm_printf ("%d \ T", a[i32]);}} I32length = I32;return *a;} INT32 INSERT_SL (INT32 b[]) {/* defined identifier, input position, array length, inserted data, loop body variable */int32 OSM = 1, i32insert_position = 0, I32insert_data = 0, i32j = 0;OSM = osm_printf ("Enter location and data to insert: \ n"), i32insert_position = Scanf_for ();/* Insert position */if ((0 > I32insert_position) || (I32length < i32insert_position)) /* If the condition of the insertion position is not satisfied */{OSM = osm_printf ("Illegal data input: \ n");} else/* inserted condition satisfies the condition */{OSM = osm_printf ("Please enter data to be inserted: \ n"); i32insert_data = Scanf_for ();/* Input inserted data*/}i32length++;/* length plus one */for (i32j = i32length; i32j > (i32insert_position-1); i32j--)//position back */{b[i32j] = b[i32j-1] ; }b[i32insert_position-1] = i32insert_data;for (i32j = 0; i32j < i32length; i32j++)/* Print out information */{if (NULL! = b[i32j]) { OSM = osm_printf ("%d\t", b[i32j]);}} OSM = osm_printf ("\ n"); return *b;} INT32 DELETE_SL (INT32 a[])/* Delete */{int32 i32i = 0, OSM = 0, i32delete_position = 0;OSM = osm_printf ("Enter location to delete: \ n"); I32dele Te_position = Scanf_for ();/* Enter the location to delete */if ((0 > I32length) | | (I32delete_position > I32length)) /* Condition */{OSM = osm_printf ("Illegal data Entered");} else{i32length--;/* length minus one */for (i32i = i32delete_position-1; i32i < i32length; i32i++)/* data processing */{a[i32i] = a[i32i+ 1];}} for (i32i = 0; i32i < i32length; i32i++)/* Print out information */{if (0 <= i32i) {if (NULL! = A[i32i]) {OSM = osm_printf ("%d\t", A[i32i]);}}} return *a;} INT32 ADD_SL (INT32 a[])/* Append */{int32 OSM = 1, i32add_data, i32i; OSM = osm_printf ("Input data to append: \ n"); i32add_data = Scanf_for ();/* Input appended elements */i32length++;/* Length plus 1 */a[i32length-1] = i32add_data;/* Direct Assignment */for (i32i = 0; i32i < i32length; i32i++)/* Print out information */{if (NULL! = a[ I32i]) {OSM = osm_printf ("%d\t", A[i32i]);}} return *a;} INT32 GET_SL (INT32 a[])/* get element */{int32 OSM = 1, i32location = 0;OSM = osm_printf ("Select required location \ n"); i32location = Scanf_for (); I F (I32location > I32length) {OSM = osm_printf ("Out of range \ n");} ELSE{IF ((Null! = (i32location-1)) && (null! = a)) {OSM = osm_printf ("Gets the data:%d \ t", a[i32location-1]);}} return 0;} INT32 FIND_SL (INT32 a[])/* Find */{int32 OSM = 1,flag = 0, i32i = 0, I32elem = 0;OSM = osm_printf ("Input needs to find element: \ t"); I32elem = s Canf_for (); OSM = osm_printf ("The location of the query is:"); for (i32i = 0; i32i < i32length; i32i++) {if (I32elem = a[i32i]) {OSM = Osm_prin TF ("%d", i32i + 1); flag = 1;}} if (1! = flag) {OSM = osm_printf ("The desired data is not found!!!!!!! \ n ");} return *a;} INT32 CLEAR_SL (INT32 a[])/* empty */{a[i32length] = Null;i32length = 0;return 0;} INT32 EMPTY_SL (INT32 a[])/* interpretation is null */{int32 OSM = 1;if (0 = = i32length)/* To determine if the first is empty */{OSM = OSM_printf ("is empty \ n");} ELSE{OSM = osm_printf ("not empty \ n");} return 0;} INT32 FULL_SL (INT32 a[])/* is full */{int32 OSM = 1;if (MAXSIZE > I32length)/* Determines whether the last element is empty */{OSM = osm_printf ("not full \ n"); } ELSE{OSM = osm_printf ("already full \ n");} return 0;} INT32 NUMBER_SL (INT32 a[])/* Number of elements */{int32 OSM = 1;if (0 <= i32length) {OSM = osm_printf ("Number of elements is%d\n", i32length);} return 0;}
It took a few days to finally reach the request. All the code can be detected by Misra C. and good function
Implement various functions using the sequential table created by the array