#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
using namespace std;
typedef struct Node{
string str;
struct Node *next;
}*LinkedList,Node;
LinkedList init()
{
Node *l;
l = (Node *)malloc(sizeof(Node));
l->next = NULL;
return l;
}
void insertTail(LinkedList l,char str[]){
LinkedList p,r;
p=l;
while(p){
p=p->next;
}
for(int i=0;i<strlen(str);i++)
{
r=(LinkedList)malloc(sizeof(Node));
r->str=str[i];
p->next=r;
p=r;
p->next=NULL;
}
}
int main()
{
char str[10]={'a','b','c','d','h'};
LinkedList L=init();
insertTail(L,str);
printf(" %d", 11);
LinkedList p;
cout<<"11"<<endl; //连主函数中的cout语言都没有打印出来
p=L;
if(!p){
cout<<"00"<<endl;
}
while(p){
p=p->next;
//cout<<(p->str)<<" ";
printf(" %s", p->str);
}
return 0;
}
下面是运行效果

空空如也,什么都没有
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
using namespace std;
typedef struct Node{
string str;
struct Node *next;
}*LinkedList,Node;
LinkedList init()
{
Node *l;
l = (Node *)malloc(sizeof(Node));
l->next = NULL;
return l;
}
void insertTail(LinkedList l,char str[]){
LinkedList p,r;
p=l;
while(p){
p=p->next;
}
for(int i=0;i<strlen(str);i++)
{
r=(LinkedList)malloc(sizeof(Node));
r->str=str[i];
p->next=r;
p=r;
p->next=NULL;
}
}
int main()
{
char str[10]={'a','b','c','d','h'};
LinkedList L=init();
insertTail(L,str);
printf(" %d", 11);
LinkedList p;
cout<<"11"<<endl; //连主函数中的cout语言都没有打印出来
p=L;
if(!p){
cout<<"00"<<endl;
}
while(p){
p=p->next;
//cout<<(p->str)<<" ";
printf(" %s", p->str);
}
return 0;
}
下面是运行效果

空空如也,什么都没有
e