在这个项目中我详细写了每一步,包括怎么建立有向图以及一些他的功能的方法。
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
typedef struct node{
struct node *next;
int data;
}Node;
typedef struct{
Node *pointerNode;
int len;
}Two_sided_queue;
void init(Two_sided_queue *const twosq){
if(twosq == NULL)
return;
twosq -> pointerNode= NULL;
twosq -> len= 0;
}
int add_front(Two_sided_queue *const twosq, int new_value){
Node *newNode;
if(twosq == NULL || new_value == -1)
return 0;
newNode= (Node*)malloc(sizeof(Node));
newNode -> data= new_value;
/*if the list is empy */
if (twosq -> pointerNode == NULL)
{
newNode->next=NULL;
twosq -> pointerNode= newNode;
}else
{ /* if the list already has elements */
newNode -> next= twosq -> pointerNode;
twosq -> pointerNode= newNode;