Help 0_0

DarkStarNIIT

Dragon Quest
GameOver
Mình đang làm thử về Danh sách dữ liệu đơn
#include <conio.h>
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

typedef struct
{
int x;
}Data;

typedef struct Node
{
Data da;
Node *next;
};

typedef struct
{
int nodenumber;
Node *front,*rear;
}List;
void init(List *l)
{
l = new List;
l->front = NULL;
l->rear = NULL;
l->nodenumber = 0;
}

void insertNode(List *l,int position,Data da)
{
Node *newnode = new Node;
newnode->da = da;

if(position == 1 )
{
newnode->next = l->front;

cout<<"??????????????????";
if(l->nodenumber == 0)
{ l->rear = newnode; }

}
else if(position > 0)
{
newnode = l->rear->next;
l->rear = newnode;
if(l->nodenumber = 0)
{ l->front = newnode; }
}
else
{
Node *curr = l->front;
Node *prev = l->rear;
int index = 0;
while(index < position)
{
curr = curr->next;
prev = curr;
index++;
}
newnode->next = curr;
prev->next = newnode;
}
l->nodenumber++;
}


int main()
{
int x,position;
List *l;
Data da;


cout<<"x:";cin>>da.x;
cout<<"Position:";cin>>position;
cout<<"_______________________"<<endl;

init(l);
insertNode(l,position,da);


Node *curr = l->front;

while(curr != NULL)
{
cout<<curr->da.x;
curr = curr->next;
}

getch();
return 0;
}

mình ko thể xem được danh sách T_T , bạn nào rành cái này giúp giùm
 
Back
Top