/*
* * Code features: Create a headache not a headache linked list, and then the specific data deleted.
* This time the theme is not in the code, mainly on the creation of the linked list when the issue of the argument, hey, don't believe you have not met
*/
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>//to allocate space and free up space
Define a linked list structure
typedef struct link{
int value;
struct link *next;
}*link,linkinstance;
/** if you want to pass in a parameter to create a linked list. As follows.
* * Created:
* * One,
void Create (LINK <) is equivalent to void Create (Linkinstance *<), using references. Reference "LT" to an alias equivalent to an argument, fully manipulating the argument
Called in the main function
LINK lt;
Create (LT);
Two, this should be very familiar
void Create (Linkinstance *lt)
Called in the main function
Linkinstance lt;
Create (<);
The result is this:
:
Wrong wording ***************************************************
* * A false notation is
void Create (LINK lt)
Called in the main function:
LINK lt;
Create (LT);
Why is wrong, because LT is just a copy.
This is your result: (haha)
* * For an example,
**void Test (int a), the above error example of LT is equivalent to a, so that the above is understood.
* * called in main
**int A;
**test (a);
* * This is ... No drip.
*/
void Create (link <) {//Initialize linked list, note "<"
link temp,current;//temp temporary space for adding nodes
lt = (link) malloc ( sizeof (struct link);//Create a head node
Lt->next = null;//short node
current = lt;
int value;
printf ("input data");
//Create node
for (int i = 0; i < 4; i++) {
temp = (link) malloc (sizeof (struct LINK));
if (temp = = NULL) {
printf ("Failed to allocate space");
Exit (0);
}//ifend
scanf_s ("%d", &value);
Temp->value = value;
Current->next = temp;
Current = current->next;
}//forend
Temp->next = null;//end, who knows what you get in the space.
}
Void del (link <,int val) {//delete list element
Link forth=lt;//Save the previous element, using the drop below
link current=lt->next;
while (current = NULL) {
if (Current->value = = val) {
Forth->next = current->next;// Previous element points to the next element , skip the middle of the Forth, current (Forth->next), Current->next
Free,//release the existing Space
}
else{
forth = current;
}
Current = forth->next;//points to the next element, which is replaced.
}//whileend
}
void Printlink (link lt) {//print
LINK L = lt->next;
while (L) {
printf ("%d\t", l->value);
L = l->next;
}
}
int _tmain (int argc, _tchar* argv[])
{
LINK lt;
Create (LT);//Created, LT is the head node, the head node does not save data
del (lt,3);//Delete all 3 of this element from the linked list.
Printlink (LT);//Print
GetChar ();
return 0;
}
/*
This is a detailed explanation of the citation written by an author: http://www.cnblogs.com/Mr-xu/archive/2012/08/07/2626973.html
*/
C + + Reference and C pointers to create linked lists, binary tree troubles and differences