Complete works of the data structure sequence table (create, traverse, insert, delete, sort, etc.)

Source: Internet
Author: User

#include "stdio.h"
#include "Stdlib.h"
#include "malloc.h"


#define LIST_SIZE 100


typedef struct NODE
{
int data[list_size];
int Len;
}node,* Pnode;


void Creat_list (Pnode L)
{
int i;
int Val;
int Len;
/*
Pnode l= (pnode) malloc (sizeof (NODE));
if (l==null)
{
printf ("Dynamic memory allocation failed!") ");
Exit (-1);
}
*/
printf ("\ t Please enter the number of elements of the order table you want to establish:");
scanf ("%d", &len);
for (i=0;i<len;i++)
{
printf ("\ t Please enter the value of%d elements:", i+1);
scanf ("%d", &val);
l->data[i]=val;
}
l->len=len;
printf ("\ n");
printf ("Build table succeeded \ n");
}
void Traverse_list (Pnode L)
{
int i;
printf ("\t\t\t\t");
for (i=0;i< l->len;i++)
{

printf ("%d", l->data[i]);


}
printf ("\ n");

}
void Insert_list (Pnode L)
{
int i,j,number;
printf ("\ t Please enter what you want to insert before the first few elements:");
scanf ("%d", &i);
printf ("\ t Please enter the value you want to insert before the first few elements:");
scanf ("%d", &number);
if (I>l->len)
{
printf ("\ t you entered an illegal value \ n");
Return
}
Else
{
for (j=l->len;j>=i;j--)
{
l->data[j]=l->data[j-1];
}
l->data[i-1]=number;
l->len++;
}
printf ("Insert succeeded \ n");
Return
}


void Delete_list (Pnode L)
{
int i;
printf ("\ t Please enter the first few elements you want to delete:");
scanf ("%d", &i);
if (I>l->len)
{
printf ("\ t you entered an illegal value \ n");
Return
}
Else
{
printf ("\ t you delete the element is%d\n", l->data[i-1]);
for (; i<l->len;i++)
{
l->data[i-1]=l->data[i];
}
l->len--;
}
printf ("Delete succeeded \ n");
Return
}


void Sort_list (Pnode L)
{
int i,j,temp;
for (i=0;i<l->len-1;i++)
{
for (j=i+1;j<l->len;j++)


if (L->data[i]>l->data[j])
{
temp=l->data[i];
l->data[i]=l->data[j];
l->data[j]=temp;
}
}
printf ("Sort succeeded \ n");
}
void Play_choose (void)
{
System ("CLS");
printf ("\n\n\n\t\t.......................................\n\n\n");
printf ("\t\t 1-Build Order Table 2-Traversal order table \ n");
printf ("\t\t 3-Insert Order table 4-Delete order table \ n");
printf ("\t\t 5-Sort Element 6-Clear screen (menu only) \ n");
printf ("\t\t 7-exit \ n \ nthe");
printf ("\n\n\t\t ... \n\n\n"), and so on.------------------".
}
int main ()
{
int i;
Pnode L;
L= (pnode) malloc (sizeof (NODE));
if (l==null)
{
printf ("\ t dynamic memory allocation failed!") ");
Exit (-1);
}
Play_choose ();
while (true)
{
printf ("\n\t, select the action you want to perform:");
scanf ("%d", &i);
Switch (i)
{
Case 1: Creat_list (L); break;
Case 2: Traverse_list (L); break;
Case 3: Insert_list (L); break;
Case 4: Delete_list (L); break;
Case 5:Sort_list (L); break;
Case 6:play_choose ();p rintf ("\t\t-processed linked list: \ n"); Traverse_list (L); break;
Case 7: Exit (-1);
Default
printf ("\ t you entered an illegal value \ n \ nthe");
Break
}
}


return 0;


}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Complete works of the data structure sequence table (create, traverse, insert, delete, sort, etc.)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.