Home > Back-end >  Singly linked list for help
Singly linked list for help

Time:04-01

To develop employee information management system, it is necessary to establish an employee basic information storage structure, including the serial number of the worker, age and gender, the above information expressed in singly linked list, requirement as follows, (1) the structure of the building staff basic information segment points, creating singly linked list based on the node, the initialization of 10 employees information; (2) the traversing the list, the output information of all employees; (3) the third, the employee leaves his post, please update the list, and the output of remaining employees information,
Great god help me, just learning, singly linked list really don't understand

CodePudding user response:

I use this app # CSDN# found have technical content of the blog and friends to seek common to "C language structure and linked list, singly linked list structure, linked list traversal, lookup list element," element deletion, gathered together at https://blog.csdn.net/zhanghaiyang9999/article/details/114360628? Utm_source=app& App_version=4.5.2

CodePudding user response:

Refer to the right, the list operation, including the definition, creation, search, delete, and so on https://blog.csdn.net/zhanghaiyang9999/article/details/114360628? Utm_source=app& App_version=4.5.2

CodePudding user response:

Singly linked list data structure on data sort http://bbs.csdn.net/topics/392201633

CodePudding user response:

https://blog.csdn.net/u011238754/article/details/104839822? SPM=1001.2014.3001.5501

Can consider adding structure members

CodePudding user response:

A simple list, for reference:
 # include & lt; Stdio. H> 
# include & lt; Stdlib. H>

typedef int ElemType;

Typedef struct data {
Int num.
Int the age;
Char sex;//M W
} the Data;

Typedef struct LNode {
The Data Data;//data domain
Struct LNode * next;//pointer field
} LNode * LinkList;//LinkList for pointer to structure LNode type

Void LL_Initiate (LinkList & amp; L);//singly linked lists of initialization, construct a lead the node's empty single table

Void LL_Free (LinkList & amp; L);//release each node in the linked list

Void LL_Create_R (LinkList & amp; L, int n);//stern interpolation, to create a leading the singly linked list of nodes L

Void LL_Print LinkList (L);//output the entire list,

Void LL_InsAt (LinkList L, int I);//in a singly linked list L the position I insert a new element, the scope of the I [1, n + 1]

Void LL_DelAt (LinkList L, int I);//singly linked list L, delete the ith element, the scope of the I [1, n)

ElemType void LL_DelValue (LinkList L, e);//remove the first value for e data element


Int main ()
{
LinkList L;
Int n, I, x;

LL_Initiate (L);//initialization to construct a lead the nodes of the empty singly linked lists

Printf (" please enter a number of employee: \ n ");
The scanf (" % d ", & amp; N);//the number of input element
LL_Create_R (m, n);//create a list

Printf (" output all the employee information: \ n ");
LL_Print (L);

Printf (" please enter to insert location: \ n ");
The scanf (" % d ", & amp; i);//input to the position of the insert
LL_InsAt (L, I);
printf("\n");
LL_Print (L);

Printf (" please input the position of the element is to be deleted: \ n ");
The scanf (" % d ", & amp; i);//the location of the input element is to be deleted
LL_DelAt (L, I);
printf("\n");
LL_Print (L);

Printf (" please enter the departure of employees gonghaowu: \ n ");
The scanf (" % d ", & amp; X);//input element's value is to be deleted
LL_DelValue (L, x);
printf("\n");
LL_Print (L);

LL_Free (L);
return 0;
}



Void LL_Initiate (LinkList & amp; L)//construct a lead the nodes of the empty singly linked list
{
L=(LinkList) malloc (sizeof (LNode));
L - & gt; Next=NULL;
}

Void LL_Free (LinkList & amp; L)//release each node in the linked list
{
LinkList p=L - & gt; Next, q;
While (1) {
If (p==NULL) break;
Q=p - & gt; Next;
free(p);
P=q;
}
}

Void LL_Create_R (LinkList & amp; Int L, n)//tail interpolation, to create a leading the singly linked list of nodes L
{
LinkList r=L, s;
int i;
Printf (" % d input employee information (work number, age (M W)) : \ n ", n);
for(i=0; i{
S=(LinkList) malloc (sizeof (LNode));//generated new node
The scanf (" % d % d % c ", & amp; S - & gt; Data. The num, & amp; S - & gt; Data. The age, & amp; S - & gt; Data. Sex);//input element value
S - & gt; Next=NULL;
R - & gt; Next=s;//is inserted into the footer
R=s;//r point to the new end node
}
}

Void LL_Print LinkList (L)//output the entire linear table,
{
LinkList p;
P=L - & gt; Next;
While (p) {
Printf (" % d % d % c \ n ", p - & gt; Data. The num, p - & gt; Data. The age, p - & gt; Data. Sex);
P=p - & gt; Next;
}
printf("\n");
}

Void LL_InsAt (LinkList L, int I)//in a singly linked list L the position I insert a new element
{
LinkList s=L, p;
int k=0;
While (1) {
If (s==NULL) break;
K++;
If (k==I) {
P=(LinkList) malloc (sizeof (LNode));
Printf (" insert new employee information (work number, age (M W)) : \ n ");
The scanf (" % d % d % c ", & amp; P - & gt; Data. The num, & amp; P - & gt; Data. The age, & amp; P - & gt; Data. Sex);
P - & gt; Next=s - & gt; Next;
S - & gt; Next=p;
break;
}
S=s - & gt; Next;
}
}

Void LL_DelAt (LinkList L, int I)//in a singly linked list L, delete the ith element

{
LinkList s=L, p;
int k=0;
While (1) {
If (s==NULL) break;
K++;
If (k==I) {
P=s - & gt; Next;
If (p) {
S - & gt; Next=p - & gt; Next;
Free (p);
}
break;
}
S=s - & gt; Next;
}
}

Void LL_DelValue (LinkList L, ElemType e)//remove the first value for e data element
{
int n;
LinkList p=L, s=NULL, q;
While (1) {
If (p==NULL) break;
If (p - & gt; Data. The num==e) {//employee number
Q=p;
If (q) {
S - & gt; Next=q - & gt; Next;
Free (q);
}
break;
}
S=p;
P=p - & gt; Next;
}
}



//please input employee number:
//3
//input 3 employee information (work number, age (M W)) :
//1 25 w
//2 27 m
//3 22 m
//output all the employee information:
//1 25 w
//2 27 m
//3 22 m

//please enter to insert location:
//4
//insert the new employee information (work number, age (M W)) :
23 w//5

//1 25 w
//2 27 m
//3 22 m
23 w//5

//please input the position of the element is to be deleted:
//1

//2 27 m
//3 22 m
23 w//5

//please enter the departure of staff work number:
//3

//2 27 m
23 w//5

null
  • Related